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? Link to comment https://forums.phpfreaks.com/topic/102510-preg_match-help/ 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. Link to comment https://forums.phpfreaks.com/topic/102510-preg_match-help/#findComment-524858 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">'? Link to comment https://forums.phpfreaks.com/topic/102510-preg_match-help/#findComment-524940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.