I'm trying to make a BBCode parser, and so far I have it working well enough, but, well, not well enough.
For example, it can do this:
Bold
but it can't do this:
bold red
for some reason.
I'm using a preg_replace to match the BBCodes, but it doesn't work.
PHP Code:
$bbreplace = array (
"/(\[[Ii]\])(.+)(\[\/[Ii]\])/",
"/(\[[Bb]\])(.+)(\[\/[Bb]\])/",
"/(\[[Uu]\])(.+)(\[\/[Uu]\])/",
"/(\[[Ss]\])(.+)(\[\/[Ss]\])/",
"/(\[color=)(.+)(\])(.+)(\[\/color\])/",
"/(\[colour=)(.+)(\])(.+)(\[\/colour\])/",
"/(\[url=)(.+)(\])(.+)(\[\/url\])/",
"/(\[img\])(.+)(\[\/img\])/
");
$bbreplacements = array
("<i>\\2</i>",
"<b>\\2</b>",
"<u>\\2</u>",
"<s>\\2</s>",
"<span style=\"color:\\2\">\\4</span>",
"<span style=\"color:\\2\">\\4</span>",
"<a href=\"\\2\">\\4</a>",
"<img src=\"\\2\" />
");
$string = "[color=red][b]bold red[/b][/color]";
$newReplyContent = preg_replace($bbreplace, $bbreplacements, $string);
It will just echo it bold, but not red

. Unfortunately, the above example works perfectly, but when I use it on my site, it suddenly craps out.
What is wrong with that code? I got it from the BBCode site and adapted it a bit, but that's it.