Code:
<?php function bbcode($text) { $smilies = array( ":)" => "<img src=\").gif\" border=\"0\" alt=\"\" />", // :) ":D" => "<img src=\"D.gif\" border=\"0\" alt=\"\" />", // :D ":(" => "<img src=\"(.gif\" border=\"0\" alt=\"\" />", // :( ":'(" => "<img src=\"(2.gif\" border=\"0\" alt=\"\" />", // :'( "xD" => "<img src=\"xd.gif\" border=\"0\" alt=\"\" />", // xD ":P" => "<img src=\"p.gif\" border=\"0\" alt=\"\" />", // :P "-.-" => "<img src=\"-.gif\" border=\"0\" alt=\"\" />", // -.- ":S" => "<img src=\"s.gif\" border=\"0\" alt=\"\" />" // :S ); $regexp = array( "/\[url=(http:\/\/)?(.+)\](.+)\[\/url\]/iU" => "<a href=\"http://$2\" target=\"_blank\">$3</a>", // [url=][/url] "/\[url\](http:\/\/)?(.+)\[\/url\]/iU" => "<a href=\"http://$2\" target=\"_blank\">$2</a>", // [url][/url] "/\[img\](http:\/\/)?(.+)\[\/img\]/iU" => "<img src=\"http://$2\" border=\"0\" alt=\"\" />", // [img][/img] "/\[email\]([a-z0-9\.-_]+@[a-z0-9]+\.[a-z0-9]+)\[\/email\]/iU" => "<a href=\"mailto:$1\">$1</a>", // [email][/email] "/\[b\](.+)\[\/b\]/iU" => "<strong>$1</strong>", // [b][/b] "/\[s\](.+)\[\/s\]/iU" => "<del>$1</del>", // [s][/s] "/\[i\](.+)\[\/i\]/iU" => "<em>$1</em>", // [i][/i] "/\[u\](.+)\[\/u\]/iU" => "<ins>$1</ins>", // [u][/u] "/\[hr\]/iU" => "<hr />", // [hr] "/\[quote\](.+)\[\/quote\]/iU" => "<p><strong>Citat:</strong> \"$1\"</p>", // [quote][/quote] "/\[quote=(.+)\](.+)\[\/quote\]/iU" => "<p><strong>$1 skrev:</strong> \"$2\"</p>", // [quote=][/quote] "/\[blink\](.+)\[\/blink\]/iU" => "<span style=\"text-decoration: blink;\">$1</span>", // [blink][/blink] "/\[marquee\](.+)\[\/marquee\]/iU" => "<marquee>$1</marquee>", // [marquee][/marquee] "/\[center\](.+)\[\/center\]/iU" => "<div style=\"text-align: center;\">$1</div>", // [center][/center] "/\[right\](.+)\[\/right\]/iU" => "<div style=\"text-align: right;\">$1</div>", // [right][/right] "/\[left\](.+)\[\/left\]/iU" => "<div style=\"text-align: left;\">$1</div>", // [left][/left] "/\[color=darkred\](.+)\[\/color\]/iU" => "<span style=\"color: darkred;\">$1</span>", "/\[color=red\](.+)\[\/color\]/iU" => "<span style=\"color: red;\">$1</span>", "/\[color=orange\](.+)\[\/color\]/iU" => "<span style=\"color: orange;\">$1</span>", "/\[color=brown\](.+)\[\/color\]/iU" => "<span style=\"color: brown;\">$1</span>", "/\[color=darkred\](.+)\[\/yellow\]/iU" => "<span style=\"color: yellow;\">$1</span>", "/\[color=green\](.+)\[\/color\]/iU" => "<span style=\"color: green;\">$1</span>", "/\[color=olive\](.+)\[\/color\]/iU" => "<span style=\"color: olive;\">$1</span>", "/\[color=cyan\](.+)\[\/color\]/iU" => "<span style=\"color: cyan;\">$1</span>", "/\[color=blue\](.+)\[\/color\]/iU" => "<span style=\"color: blue;\">$1</span>", "/\[color=darkblue\](.+)\[\/color\]/iU" => "<span style=\"color: darkblue;\">$1</span>", "/\[color=indigo\](.+)\[\/color\]/iU" => "<span style=\"color: indigo;\">$1</span>", "/\[color=violet\](.+)\[\/color\]/iU" => "<span style=\"color: violet;\">$1</span>", "/\[color=white\](.+)\[\/color\]/iU" => "<span style=\"color: white;\">$1</span>", "/\[color=black\](.+)\[\/color\]/iU" => "<span style=\"color: black;\">$1</span>", "/\[size=1\](.+)\[\/size\]/iU" => "<span style=\"font-size: 18px;\">$1</span>", "/\[size=2\](.+)\[\/size\]/iU" => "<span style=\"font-size: 24px;\">$1</span>", "/\[size=3\](.+)\[\/size\]/iU" => "<span style=\"font-size: 32px;\">$1</span>", "/\[size=4\](.+)\[\/size\]/iU" => "<span style=\"font-size: 48px;\">$1</span>", "/\[size=\-1\](.+)\[\/size\]/iU" => "<span style=\"font-size: 12px;\">$1</span>", "/\[size=\-2\](.+)\[\/size\]/iU" => "<span style=\"font-size: 10px;\">$1</span>", "/\[youtube\](.+)\[\/youtube\]/iU" => "<object width=\"425\" height=\"344\"><param name=\"movie\" value=\"http://www.youtube.com/v/$1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><embed src=\"http://www.youtube.com/v/$1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"425\" height=\"344\"></embed></object>", // [youtube][/youtube] "/\[code\](.+)\[\/code\]/eiU" => "highlight_string(\"$1\", true)" // [ code ][ /code ] ); foreach ($regexp as $regexps => $regexp_replacements) { $text = preg_replace($regexps, $regexp_replacements, $text); } foreach ($smilies as $smilies2 => $smilies_replacements) { $text = str_ireplace($smilies2, $smilies_replacements, $text); } return $text; } ?>
Code:
"/\[img=(.+)\](.+)\[\/img\]/iU" => "<br /><br /><center><table cellpadding=\"3px\" class=\"imageDiv\"><tr><td><img src=\"$1\" alt=\"\" border=\"0\"</img></td></tr><tr><td><small>$2</small></td></tr</table></center><br /><br />", // [quote=][/quote]
Comment