This is a simple PHP function to convert BBCODE style text into valid HTML. Useful for news management scripts/cms's/forums etc.
Simple call the bbCode() function when displaying the text to the end user.
Comments and feedback is always nice.PHP Code:function bbCode($text){
$text = str_ireplace( "<BR>", "<br />", $text ); //Valid xHTML
$text = preg_replace( "#\[(left|right|center)\](.+?)\[/\\1\]#is" , "<div align=\"\\1\">\\2</div>", $text ); //Aligns text ([center]text[/center], [left]text[/left], [right]text[/right]
$text = preg_replace( "#\[(b|i|u|s)\](.+?)\[/\\1\]#is" , "<\\1>\\2</\\1>", $text ); //Makes text bold/italic/underlined/strikethrough [i]text[/i]
$text = preg_replace( "#\[(url)\=(.+?)\](.*?)\[/\\1\]#is" , "<a href=\"\\2\">\\3</a>", $text ); //Link - custom text as link ([url=address]text[/url])
$text = preg_replace( "#\[(url)\](.*?)\[/\\1\]#is" , "<a href=\"\\2\">\\2</a>", $text ); //Link - displays address as link ([url]address[/url])
$text = preg_replace( "#\[(img)\](.*?)\[/\\1\]#is" , "<img src=\"\\2\" />", $text ); //Images
return $text;
}


LinkBack URL
About LinkBacks
Reply With Quote



