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 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 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 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 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.