11-08-2009, 07:44 PM
Very good tut.
I use this simple function whenever I like to parse the BBcode.
Hopefully this is also an helpful idea
I use this simple function whenever I like to parse the BBcode.
PHP Code:
<?
function bbcode($text){
$text = str_replace('<', '<', $text);
$text = str_replace('>', '>', $text);
$text = str_replace('"', """, $text);
$text = str_replace('[b]', '<b>', $text);
$text = str_replace('[/b]', '</b>', $text);
$text = str_replace('[i]', '<i>', $text);
$text = str_replace('[/i]', '</i>', $text);
$text = str_replace('[u]', '<u>', $text);
$text = str_replace('[/u]', '</u>', $text);
$text = str_replace('[url=', '<a href="', $text);
$text = str_replace('[/url]', '</a>', $text);
$text = str_replace('[img]', '<img src="', $text);
$text = str_replace('[/img]', '">', $text);
$text = str_replace('[c]', '<center>', $text);
$text = str_replace('[/c]', '</center>', $text);
$text = str_replace(']', '">', $text);
$text = str_replace('[B]', '<b>', $text);
$text = str_replace('[/B]', '</b>', $text);
$text = str_replace('[I]', '<i>', $text);
$text = str_replace('[/I]', '</i>', $text);
$text = str_replace('[U]', '<u>', $text);
$text = str_replace('[/U]', '</u>', $text);
$text = str_replace('[URL=', '<a href="', $text);
$text = str_replace('[/URL]', '</a>', $text);
$text = str_replace('[IMG]', '<img src="', $text);
$text = str_replace('[/IMG]', '">', $text);
$text = str_replace('[C]', '<center>', $text);
$text = str_replace('[/C]', '</center>', $text);
$text = str_replace(']', '">', $text);
$text = nl2br($text);
$text = trim($text);
return $text;
}
?>
Hopefully this is also an helpful idea