moon 111 Posted April 23, 2008 Share Posted April 23, 2008 For some reason the following code is returning Array ( ) <?php $subject = '<div class="story"> <h5> <a href="http://www.nytimes.com/2008/04/23/world/europe/23coal.html?hp">Europe Turns to Coal Again, Raising Alarms on Climate</a> </h5> <div class="byline">By ELISABETH ROSENTHAL</div> <p class="summary">European countries plan to use coal, generally the dirtiest fuel on earth, in new power plants.</p>'; $regex = '|<div class="story">\s++<h5>\s++<a href="([^"]*)">([^<]*)</a>\s++</h5>\s++ <div class="byline">([^<]*)</div>\s++<p class="summary"> ([^<]*)</p>|'; preg_match($regex, $subject, $match); print_r($match); ?> Help? Quote Link to comment Share on other sites More sharing options...
obsidian Posted April 23, 2008 Share Posted April 23, 2008 Try a pattern like this instead: |<div class="story">\s*<h5>\s*<a href="([^"]*)">([^<]*)</a>\s*</h5>\s* <div class="byline">([^<]*)</div>\s*<p class="summary"> ([^<]*)</p>|' Your match for spaces seemed a little wonky. You probably need to use the * to allow for zero or more. It seems to work just fine this way. Quote Link to comment Share on other sites More sharing options...
moon 111 Posted April 23, 2008 Author Share Posted April 23, 2008 Thanks! One more thing: how can I make it so that it will still match if it has '<div class="kicker">American Exception</div>' after '|<div class="story">'? 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.