Sat, June 10, 2023
https://devcodepro.comdevcodepro
Home · Latest · Trends
16

PHP BBCode parser

<?php
//based on bbcode2htm plugin
//$mytext = '[font=Georgia]Font family example[/font] <br />
//[color=#BB0000]Font color example[/color] <br />
//[size=24]Font size example[/size] <br />
//[b]Bold text[/b] <br />
//[i]Italic text[/i] <br />
//[u]Underlined text[/u] <br />
//[s]Text with a strikethrough[/s] <br />
//[small]Small defines smaller text[/small] <br />
//[align=right]Align right example[/align] <br />
//[align=center]Center example[/align] <br />
//[code]//foreach ($array as $item) {
//  echo "$item\n";
//  $array[] = $item;
//}
//[/code] <br />
//[php]
//foreach ($array as $item) {
//  echo "$item\n";
//  $array[] = $item;
//}
//[/php] <br />
//[quote]blockquote - HTML Block Quotation Element[/quote] <br />
//This is[sub] subscript[/sub] and [sup]superscript[/sup] example <br />
//[[email protected]]Email link example[/email] <br />
//[img]https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png[/img] <br />
//[url=https://www.google.com]Link example[/url] <br />';
function show_BBcode($code) {
 $input = array(
  '/(?<!\\\\)\[font(?::\w+)?=(.*?)\](.*?)\[\/font(?::\w+)?\]/si' => "<span style=\"font-family:\\1\">\\2</span>",
  '/(?<!\\\\)\[color(?::\w+)?=(.*?)\](.*?)\[\/color(?::\w+)?\]/si' => "<span style=\"color:\\1\">\\2</span>",
  '/(?<!\\\\)\[size(?::\w+)?=(.*?)\](.*?)\[\/size(?::\w+)?\]/si' => "<span style=\"font-size:\\1\">\\2</span>",
  '/(?<!\\\\)\[b(?::\w+)?\](.*?)\[\/b(?::\w+)?\]/si' => "<strong>\\1</strong>",
  '/(?<!\\\\)\[i(?::\w+)?\](.*?)\[\/i(?::\w+)?\]/si' => "<i>\\1</i>",
  '/(?<!\\\\)\[u(?::\w+)?\](.*?)\[\/u(?::\w+)?\]/si' => "<u>\\1</u>",
  '/(?<!\\\\)\[s(?::\w+)?\](.*?)\[\/s(?::\w+)?\]/si' => "<s>\\1</s>",
  '/(?<!\\\\)\[small(?::\w+)?\](.*?)\[\/small(?::\w+)?\]/si' => "<small>\\1</small>",
  '/(?<!\\\\)\[align(?::\w+)?=(.*?)\](.*?)\[\/align(?::\w+)?\]/si' => "<div style=\"text-align:\\1\">\\2</div>",
  '/(?<!\\\\)\[center(?::\w+)?\](.*?)\[\/center(?::\w+)?\]/si' => "<div style=\"text-align:center\">\\1</div>",
  '/(?<!\\\\)\[code(?::\w+)?\](.*?)\[\/code(?::\w+)?\]/si' => "<div style=\"font-family: Consolas,Monaco,Lucida Console,monospace;font-size: 13px;background-color:#eff0f1;padding:10px;\">Code:<pre class=\"prettyprint linenums\">\\1</pre></div>",
  '/(?<!\\\\)\[php(?::\w+)?\](.*?)\[\/php(?::\w+)?\]/si' => "<div style=\"font-family: 'Courier New',Consolas,Monaco,monospace;font-size: 12px;background-color:#eff0f1;padding:10px;\">Code:<pre class=\"prettyprint linenums\">\\1</pre></div>",
  '/(?<!\\\\)\[quote(?::\w+)?\](.*?)\[\/quote(?::\w+)?\]/si' => "<blockquote style=\"font-size: 15px;background-color:lightyellow;padding:16px;\">\\1</blockquote>",
  '/(?<!\\\\)\[sub(?::\w+)?\](.*?)\[\/sub(?::\w+)?\]/si' => "<sub>\\1</sub>",
  '/(?<!\\\\)\[sup(?::\w+)?\](.*?)\[\/sup(?::\w+)?\]/si' => "<sup>\\1</sup>",
  '/(?<!\\\\)\[email(?::\w+)?=(.*?)\](.*?)\[\/email(?::\w+)?\]/si' => "<a href=\"mailto:\\1\">\\2</a>",
  '/(?<!\\\\)\[img(?::\w+)?\](.*?)\[\/img(?::\w+)?\]/si' => "<img src=\"\\1\" alt=\"\\1\" />",
  '/(?<!\\\\)\[url(?::\w+)?=(.*?)?\](.*?)\[\/url(?::\w+)?\]/si' => "<a href=\"\\1\" target=\"_blank\">\\2</a>");
 $code = preg_replace(array_keys($input), array_values($input), $code);
 return $code;
}
//echo show_BBcode($mytext);
?>
AD ยท www.interserver.net/r/240055 

Interserver | Standard & VPS Cloud Hosting | $2.50 /Month

Flexible VPS hosting platform to deploy your online projects. Economical and balanced between processor cores, memory and storage
rated 16 times (16) (0)
comments: 0 / hits: 4126  / 4 years ago, wed, dec 11, 19, 10:46:24
More From » PHP
 

Comments

There are no comments for this Snippet yet
Only authorized users can post. Please sign in first, or register a free account
Login with Google
 
Share
Posted
pport
Member since Dec 11, 2019
Total Code Snippets: 7
Total Comments: 0
Location: Hartford, Connecticut
pport snippets
3 years ago, tue, nov 24, 20, 8:31:52
jQuery(function(){ jQuery('.showsinglediv').click(function(){ jQuery('#divfirst').toggle(); jQuery('#divsecond').toggle(); }); }); //<a class="showsinglediv">Click</a> //<div id="divfirst">First Div</div> //<div id="divsecond" style="display: none">Second Div</div>
comments: 0 / hits: 931
4 years ago, thu, dec 26, 19, 1:40:52
<table> <tr> <td>Sans-serif fonts</td> <td>Arial, Comic Sans, Trebuchet MS, Verdana</td> </tr> <tr> <td>Serif fonts</td> <td>Georgia, Times New Roman</td> </tr> <tr> <td>Monospace fonts</td> <td>Courier New</td> </tr> </table>
comments: 0 / hits: 3110
3 years ago, wed, feb 12, 20, 2:14:06
<table> <tr> <td> Option 1 </td> <td> Open C:\xampp\readme.txt <blockquote>+ PHP 7.4.1 (VC15 X86 64bit thread safe) + PEAR + Apache 2.4.41 + MariaDB 10.4.11 + phpMyAdmin 5.0.1 + Tomcat 7.0.99 + XAMPP Control Panel Version 3.2.4. + OpenSSL 1.1.0g + ADOdb 518a</blockquote> </td> </tr> <tr> <td> Option 2 </td> <td> Create a php file phpinfo.php (C:\xampp\htdocs\phpinfo.php) and save file with this code: <blockquote><?php phpinfo(); ?></blockquote> Point your browser to http://localhost/phpinfo.php </tr> <tr> <td> Option 3 </td> <td> Point your browser to http://localhost/phpmyadmin/index.php Check Web Server info in right sidebar: <blockquote>Apache/2.4.41 (Win64) OpenSSL/1.1.1c PHP/7.4.1 Database client version: libmysql - mysqlnd 7.4.1 PHP extension: mysqli Documentation curl Documentation mbstring Documentation PHP version: 7.4.1</blockquote> </td> </tr> </table>
comments: 0 / hits: 6843
3 years ago, tue, nov 24, 20, 8:40:57
.myclass:not(:last-child)::after { content: ", "; } /* <span class="myclass">class1</span> <span class="myclass">class2</span> <span class="myclass">class3</span> */
comments: 0 / hits: 806
CSS
2 years ago, sun, jan 3, 21, 3:39:57
.myelement { background: rgb(68, 68, 68) url("images/myimage.jpg") no-repeat scroll center center / cover; width: 100%; display: block; } @media (min-width: 576px) { .myelement { height: 240px; } } @media (min-width: 768px) { .myelement { height: 380px; } } @media (min-width: 992px) { .myelement { height: 480px; } } @media (min-width: 1200px) { .myelement { height: 540px; } }
comments: 0 / hits: 456
CSS
2 years ago, mon, jan 4, 21, 11:38:12
<div class="card"> <div class="card-header"> <div class="row"> <div class="col-8">Col 8</div> <div class="col-2 text-left">Col 2</div> <div class="col-2">Col 2</div> </div> </div> <div class="card-block">Card Body</div> </div>
comments: 0 / hits: 479