View Full Version : regular expression for [quote] bbcode

05-20-2004, 10:58 AM
So far i have

$str = eregi_replace('\[quote=([^]]+)\]([^\[]+)\[/quote\]', '<b>\\1 says:</b> <br /><table cellspacing="0" cellpadding="3" style="border: 1 solid; border-color: #cccccc; background-color: #ffffff;"><tr><td>\\2</td></tr></table>', $str);

this works if you are quoting someone who hasn't quoted someone in their message.
If i wanted to quote someone who already used the [quote] tag in their message, it doesn't do it right.
What i was hoping to do with the regular expression is instead of this line
which is take any character OTHER than left bracket [
i want it to say take any character OTHER than [quote
but i don't know how to do this
obviously i have tried
that doesn't work
i don't know regular expressions very well, can anyone inform me?

05-20-2004, 11:23 AM
hmm. i didn't realy took a close look at the regex, but i would simply run the eregi_replace() a few times. Like

for($i=0; $i<=100; $i++){ //assuming you'll have at most 100 levels of nested quotes
if ($str==$original){
break; // so the loop is exited if no replaces have been made
} else {
$original = $str; //so the replace will be repeated on the result of this replace

05-20-2004, 11:40 AM
hey thanks!
didn't even think to do it that way :-)

05-20-2004, 01:42 PM
You're welcome.

It's a little usefull hack which keeps it all simple without a lott of extra overhead. Might even be the only sollution for your particular question.