homepage Welcome to WebmasterWorld Guest from 107.21.187.131
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
preg match all question
turbohost




msg:3853452
 10:07 pm on Feb 19, 2009 (gmt 0)

Hi guys,

Got a question about preg_match_all. I'm using preg_match_all to fetch all the items in a text which are between curly brackets. There is one problem ... sometimes there are curly brackets between other curly brackets.

Here is an example:
preg_match_all works with this one {bla}{bla}{bla}
but not with this one {bla{bla}bla}

This is the code I use
preg_match_all('/\{(.+?)\}/ims',$article,$itemis);

Any suggestions ?

 

whoisgregg




msg:3853454
 10:09 pm on Feb 19, 2009 (gmt 0)

What would you like the output to be when that happens?

turbohost




msg:3853469
 10:18 pm on Feb 19, 2009 (gmt 0)

if this is the input {bla1{bla2}bla3} then I would like to have this 'bla1{bla2}bla3' and this 'bla2' as output

turbohost




msg:3853477
 10:30 pm on Feb 19, 2009 (gmt 0)

is this possible ?

turbohost




msg:3853507
 11:10 pm on Feb 19, 2009 (gmt 0)

getting a headache of this one :-/ somebody ?

coopster




msg:3853525
 11:39 pm on Feb 19, 2009 (gmt 0)

I just answered a very similar question yesterday in the Perl forum. You can use recursion [webmasterworld.com] to match nested patterns.

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