Forum Moderators: coopster

Message Too Old, No Replies

preg replace help needed

         

darkage

9:24 pm on Dec 2, 2008 (gmt 0)

10+ Year Member



I'm trying to remove all bbcode tags in my forum post with the following:

$patterns[0] = "/\[.+\]/i";
$replacements[0] = "";
$postText = preg_replace($patterns, $replacements, $postText);

However when running into the following it will match the entire string below (and thereby remove it):


[tag1][tag2][/tag2][/tag1]

Instead it should have matched tag1 then tag2 then... and so on.

Any input on what I can do to accomplish this without trying to match each individual tag?

Thanks in advance.

darkage

7:44 am on Dec 3, 2008 (gmt 0)

10+ Year Member



it seems i need to change the pattern from greedy to ungreedy by using the ? quantifier or /U.

vincevincevince

8:25 am on Dec 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you're right - add ? after the +