Synkc
Active Member
- Messages
- 1,765
- Reaction score
- 0
- Points
- 36
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.
Simple call the bbCode() function when displaying the text to the end user.
PHP:
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;
}
Last edited: