BB Koder och Smileys
Den här funktionen tolkar BB kod till HTML.
<?php
echo nl2br(bbcode(htmlspecialchars($info['profil'])));
function bbcode($text){
// Smileys
$text = str_replace(":)", "<img src=\"http://www.fuska.se/forum/style_emoticons/default/smile.gif\">", $text);
$text = str_replace(":(", "<img src=\"http://www.fuska.se/forum/style_emoticons/default/sad.gif\">", $text);
// BB Koder
$regexp = array(
"/\[b\](.+)\[\/b\]/iU" => "<strong>$1</strong>", // [b]Fet Text[/b]
"/\[s\](.+)\[\/s\]/iU" => "<del>$1</del>", // [s]Genomstruken Text[/s]
"/\[u\](.+)\[\/u\]/iU" => "<ins>$1</ins>", // [u]Understruken Text[/u]
"/\[i\](.+)\[\/i\]/iU" => "<em>$1</em>", // [i]Kursiv Text[/i]
"/\[url=(http:\/\/)?(.+)\](.+)\[\/url\]/iU" => "<a href=\"http://$2\" target=\"_blank\">$3</a>", // [url=http://www.wasd.nu]WASD.nu[/url]
"/\[url\](http:\/\/)?(.+)\[\/url\]/iU" => "<a href=\"http://$2\" target=\"_blank\">$2</a>", // [url]http://www.wasd.nu[/url]
"/\[img\](http:\/\/)?(.+)\[\/img\]/iU" => "<img src=\"http://$2\" border=\"0\" alt=\"\" />", // [img=www.wasd.nu/bild.png]
"/\[hr\]/i" => "<hr />", // [hr]
"/\[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]Video ID[/youtube]
"/\[quote=(.+)\](.+)\[\/quote\]/iU" => "<p><strong>$1 skrev:</strong> \"$2\"</p>", // [quote=WASD]QUOTE[/quote]
"/\[color=red\](.+)\[\/color\]/iU" => "<span style=\"color: red;\">$1</span>", // [color=red]Röd Text[/color]
"/\[spoiler\](.+)\[\/spoiler\]/iU" => "<span style=\"color: #000000; background: #000000\">$1</span>", // [spoiler]Hidden text[/spoiler]
);
foreach ($regexp as $regexps => $regexp_replacements){
$text = preg_replace($regexps, $regexp_replacements, $text);
}
return $text;
}
?>