homepage Welcome to WebmasterWorld Guest from 54.242.241.20
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
preg replace help needed
darkage

5+ Year Member



 
Msg#: 3798571 posted 9:24 pm on Dec 2, 2008 (gmt 0)

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

5+ Year Member



 
Msg#: 3798571 posted 7:44 am on Dec 3, 2008 (gmt 0)

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

vincevincevince

WebmasterWorld Senior Member vincevincevince us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3798571 posted 8:25 am on Dec 3, 2008 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved