Advertisement
opsftw

MyBB Code Interpreter

Feb 24th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1.     public function formatPost( $text ) {
  2.         // BBcode array
  3.         $find = array(
  4.             '~\[center\](.*?)\[/center\]~si',
  5.             '~\[right\](.*?)\[/right\]~si',
  6.             '~\[b\](.*?)\[/b\]~si',
  7.             '~\[i\](.*?)\[/i\]~si',
  8.             '~\[u\](.*?)\[/u\]~si',
  9.             '~\[quote\](.*?)\[/quote\]~si',
  10.             '~\[size=(.*?)\](.*?)\[/size\]~si',
  11.             '~\[color=(.*?)\](.*?)\[/color\]~si',
  12.             '~\[url\]((?:ftp|https?)://.*?)\[/url\]~si',
  13.             '~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]~si'
  14.         );
  15.         // HTML tags to replace BBcode
  16.         $replace = array(
  17.             '<center>$1</center>',
  18.             '<span style="float:right">$1</span>',
  19.             '<b>$1</b>',
  20.             '<i>$1</i>',
  21.             '<span style="text-decoration:underline;">$1</span>',
  22.             '<pre>$1</'.'pre>',
  23.             '<span style="font-size:$1px;">$2</span>',
  24.             '<span style="color:$1;">$2</span>',
  25.             '<a href="$1">$1</a>',
  26.             '<img src="$1" alt="" />'
  27.         );
  28.         // Replacing the BBcodes with corresponding HTML tags
  29.         return nl2br(preg_replace($find,$replace,$text));
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement