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> 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'; 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). 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. 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
Archived
This topic is now archived and is closed to further replies.