I use the following coding for [ size ] and [ color ] bb-code:
$message = eregi_replace("\\[size=([^\\[]*)\\]([^\\[]*)\\[/size\\]","<span style=\"font-size: \\1px;\">\\2</span>",$message);
$message = eregi_replace("\\[color=([^\\[]*)\\]([^\\[]*)\\[/color\\]","<font color=\"\\1\">\\2</font>",$message);
When I input the following bb-codes, only the first one really works, the second one only works for the [ color ] and the other two don't do anything:
[color=red][size=18]test[/size][/color]
[size=18][color=red]test[/color][/size]
[size=18][color=red]test[/size][/color]
[color=red][size=18]test[/color][/size]
I don't really understand what the problem is... If anyone is willing to take a look at the coding and tell what I did wrong, I'd be really gratefull! :D
Just wondering, why don't you just use the <font> tag for the size? :-/
i'm not quite sure.... but would it make a difference?
Less html... but other than that no.
ereg and eregi are much slower than preg
if you can, you should use preg_replace instead
I'm pretty sure that the last two *shouldn't* work. It may be possible, but I think it's bad practice to start tag A and then start tag B and then close tag A without closing tab B first. Tags should be nested or not nested. It seems like this happens most often with < form > tags and < tables >. Although there's probably nothing wrong with that, it really bugs me when I see that.
I have a feeling that one function is taking precedence over the other. That is, in your code you are first doing size, then color. your first BBC example works. I bet if you switched your logic so that you were doing color first, your second BBC would be the one working correctly.
Probably what's happening is that when you first do size, its doing something to mess up the tag that's nested inside it.
$message = preg_replace('~\[size=(.+?)\](.+?)\[/size\]~is','<span style="font-size: $1px;">$2</span>', $message);
$message = preg_replace('~\[color=(.+?)\](.+?)\[/color\]~is','<font color="$1">$2</font>', $message);
-[Unknown]