insomnomaniac Posted July 15, 2010 Share Posted July 15, 2010 Hi All, I'm new to regex and need some help. I'm trying to parse through a web page to find all the strings below that are separated by new lines: <h3 class="listing-price"> $21,555 </h3> $pattern = 'XXX'; preg_match_all($pattern, $content, $output); Thanks! Quote Link to comment Share on other sites More sharing options...
premiso Posted July 15, 2010 Share Posted July 15, 2010 What do you want, the dollar amount? The 's' modifier will treat the string as one long string / ignores new lines (if my terminology is correct). $pattern = '~class="listing-price">(.*)</h3>~isU'; May give you what you are after, not really sure as you did not specify your expected output.. Quote Link to comment Share on other sites More sharing options...
Zane Posted July 15, 2010 Share Posted July 15, 2010 use the multiline modifier in your regex pattern $pattern = "/XXX/m" the m is the modifier, it goes after the delimiters (the slashes) Quote Link to comment Share on other sites More sharing options...
insomnomaniac Posted July 15, 2010 Author Share Posted July 15, 2010 What do you want, the dollar amount? The 's' modifier will treat the string as one long string / ignores new lines (if my terminology is correct). $pattern = '~class="listing-price">(.*)</h3>~isU'; May give you what you are after, not really sure as you did not specify your expected output.. Sorry about that...Yes, I'm trying to get the dollar amount without the '$' symbol. So in my example I'm trying get '21,555'. Your pattern works but it includes the '$' with a space in front of it. Thanks! Quote Link to comment Share on other sites More sharing options...
premiso Posted July 15, 2010 Share Posted July 15, 2010 You couldn't figure out the new pattern? el sigh. $pattern = '~class="listing-price">.*\$(.*)</h3>~isU'; Quote Link to comment Share on other sites More sharing options...
insomnomaniac Posted July 15, 2010 Author Share Posted July 15, 2010 You couldn't figure out the new pattern? el sigh. $pattern = '~class="listing-price">.*\$(.*)</h3>~isU'; Thank you sir! Quote Link to comment Share on other sites More sharing options...
ZachMEdwards Posted July 16, 2010 Share Posted July 16, 2010 The 's' modifier will make the . (dot) match newlines. 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.