playwright Posted July 14, 2010 Share Posted July 14, 2010 Hello!! i want to grab all content that is between the tags <-- message --> and <!-- message -->.. I have found the right pattern to do so which is something like preg_match_all('%<!-- message -->(.+)<!-- / message -->%si',$x,$y) but it seems that it grabs all content from the 1st tag <-- message --> untill the last tag <!-- message --> in one record. However, there are many more such tags between the first and the last encounter and the thing is that i want to fill my array with all this records separately..Any ideas??? Quote Link to comment https://forums.phpfreaks.com/topic/207748-grab-content/ Share on other sites More sharing options...
Psycho Posted July 14, 2010 Share Posted July 14, 2010 Your expression is greedy. Do some research for greedy vs. non-greedy regular expressions. But, the simple fix if to add a question mark as indicated to make it non-greedy: preg_match_all('%<!-- message -->(.+?)<!-- / message -->%si',$x,$y) Quote Link to comment https://forums.phpfreaks.com/topic/207748-grab-content/#findComment-1086023 Share on other sites More sharing options...
playwright Posted July 14, 2010 Author Share Posted July 14, 2010 You 're right..I used the pattern you said and it works fine now!! Quote Link to comment https://forums.phpfreaks.com/topic/207748-grab-content/#findComment-1086026 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.