Hey,
Does anyone know a good BB Code function that parses it no matter if it is on the same line or not.
I currently have
However, it only works if its on the same line.PHP Code:
<?php
function bb($str)
{
$str = preg_replace('#\[b\](.*?)\[/b\]#i','<strong>$1</strong>',$str);
$str = preg_replace('#\[i\](.*?)\[/i\]#i','<em>$1</em>',$str);
$str = preg_replace('#\[u\](.*?)\[/u\]#i','<u>$1</u>',$str);
$str = preg_replace('#\[align=(.*?)\](.*?)\[/align\]#i','<div align="$1">$2</div>',$str);
$str = preg_replace('#\[color=(.*?)\](.*?)\[/color\]#i','<font color="$1">$2</font>',$str);
$str = preg_replace('#\[font=(.*?)\](.*?)\[/font\]#i','<font face="$1">$2</font>',$str);
$str = preg_replace('#\[size=(.*?)\](.*?)\[/size\]#i','<font size="$1">$2</font>',$str);
$str = preg_replace('#\[img\](.*?)\[/img\]#i','<img src="$1" />',$str);
$str = preg_replace('#\[code\](.*?)\[/code\]#i','<fieldset><legend>Code</legend><br />$1</fieldset>',$str);
$str = preg_replace('#\[quote\](.*?)\[/quote\]#i','<fieldset><legend>Quote</legend><br />$1</fieldset>',$str);
$str = preg_replace('#\[quote=(.*?)\](.*?)\[/quote\]#i','<fieldset><legend>Quote - $1</legend><br />$2</fieldset>',$str);
$str = preg_replace('#\[url\](.*?)\[/url\]#i','<a href="$1" target="_blank">$1</a>',$str);
$str = preg_replace('#\[url=(.*?)\](.*?)\[/url\]#i','<a href="$1" target="_blank">$2</a>',$str);
return $str;
}
?>
Thanks for any help =]