< ?php
function BBCode($text)
{
/**
* The following array has the structure Key => Value. The key is the item that will be typed e.g [b] the value will be the html equivilant.
*/
$BBCode = array("&" => "&", "< " => "<", ">" => ">", "[b]" => "",
"[/b]" => "", "[i]" => "", "[/i]" => "", "[u]" => "", "[/u]" =>
"", "[img]" => " "’>"); // Comment Above
$parsedtext = str_replace(array_keys($BBCode), array_values($BBCode), $text); //This function will get the input string. and then the keys and values of the array above. It will then replace them with the html equivilant.
return $parsedtext; // Return $parsedtext.
}
?>
ESEMPIO APPLICATO
< ?php
$text = BBCode("[b][u]HELLO[/u][/b]"); // Execute Function
echo $text; // Echo $text.
?>
fonte: www.sastgroup.com





