This function let u use like ['u]poopoo['/u] (without ' ).
this will result in = poopoo
really simple!
<?
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;
}
?>
just a suggestion, but to decrease the size of the script, consider sticking the search and replacements into arrays. also, just using str_replace (or as Hawkee suggested, str_ireplace), means that you aren\'t actually validating the input, meaning that the user could possibly break up the format of the output page by adding too many closing or opening tags. A preg_replace would be better, that way if there are any mismatches, they aren\'t replaced at all.