atticus Posted November 20, 2009 Share Posted November 20, 2009 Here is the regex: $regex = '~<p class="product-attr">(.+)</p>~'; This is what I am trying to grab: <p class="product-attr"> W/ features and more text to put into my variable </p> Quote Link to comment https://forums.phpfreaks.com/topic/182325-solved-preg_match_all-regex-problemi-just-want-everthing-in-between/ Share on other sites More sharing options...
rajivgonsalves Posted November 20, 2009 Share Posted November 20, 2009 use the 's' modifier $regex = '~<p class="product-attr">(.+)</p>~s'; Quote Link to comment https://forums.phpfreaks.com/topic/182325-solved-preg_match_all-regex-problemi-just-want-everthing-in-between/#findComment-962128 Share on other sites More sharing options...
nrg_alpha Posted November 20, 2009 Share Posted November 20, 2009 Try making that + quantifier lazy (.+?), otherwise, if there is multiple p tags in that line, the dot will greedily match all the way to the end, then backtrack till it matches the final </p> (which may not be the correct one). You can read about the pitfalls of greedy quantifiers here (post #11 and #14 helps illustrate this). And as raj mentioned.. possibly using the s modifier might help (assuming your p tag is spead across multiple lines). Quote Link to comment https://forums.phpfreaks.com/topic/182325-solved-preg_match_all-regex-problemi-just-want-everthing-in-between/#findComment-962130 Share on other sites More sharing options...
atticus Posted November 20, 2009 Author Share Posted November 20, 2009 You guys really know you stuff...and you actually answered my next question before I could even ask it. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/182325-solved-preg_match_all-regex-problemi-just-want-everthing-in-between/#findComment-962137 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.