I use this function for BBcode parsing:
function bbcode ($message) {
$search = array(
'@\[(?i)b\](.*?)\[/(?i)b\]@si',
'@\[(?i)i\](.*?)\[/(?i)i\]@si',
'@\[(?i)u\](.*?)\[/(?i)u\]@si',
'@\[color=rgb(.*?)\](.*?)\[\/color\]@si',
'@\[quote=](.*?)\[\/quote\]@si',
'@\[li](.*?)\[\/li\]@si',
'@\[ul](.*?)\[\/ul\]@si',
);
$replace = array(
'<b>\\1</b>',
'<i>\\1</i>',
'<u>\\1</u>',
'<span style=\"color:rgb\\1\">\\2</span>',
'<span class=\"quote">\\1</span>',
'<li>\\1</li>',
'<ul>\\1</ul>',
);
return preg_replace($search , $replace, $message);
}
In most cases it works ok, but not always.
For example:
[color=rgb(102, 0, 102)]H[color=rgb(204, 0, 0)]e[/color]llo[/color]
The result is:
<span style="color:rgb(102, 0, 102)">H[color=rgb(204, 0, 0)]e</span>llo[/color]
As you can see, only the first [color=...][/color] has been converted to html. The second stays as it is. Any ideas?