jarvis Posted January 11, 2013 Share Posted January 11, 2013 Hi All, I hope someone can help. I've the following code which retrieves info from a Wordpress RSS feed nad converts it into PHP: <?php $rss = new DOMDocument(); $rss->load('http://wordpress.org/news/feed/'); $feed = array(); foreach ($rss->getElementsByTagName('item') as $node) { $item = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue, ); array_push($feed, $item); } $limit = 5; for( $x=0; $x<$limit; $x++ ) { $title = str_replace(' & ', ' & ', $feed[$x]['title']); $link = $feed[$x]['link']; $description = $feed[$x]['desc']; $description = substr($description, 0, 500); $date = date('l F d, Y', strtotime($feed[$x]['date'])); echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />'; echo '<small><em>Posted on '.$date.'</em></small></p>'; echo '<p>'.$description.'</p>'; } ?> All works well and grabs what I need. However, at the bottom of the returned info, I get another loop of results which shows: Posted on Thursday January 01, 1970 Posted on Thursday January 01, 1970 Posted on Thursday January 01, 1970 But I can't see how or why this gets created? Can someone assist? TIA Link to comment https://forums.phpfreaks.com/topic/273007-rss-to-php-date-issue/ Share on other sites More sharing options...
jarvis Posted January 11, 2013 Author Share Posted January 11, 2013 Solved! The limit was set to 5 but the feed only had 2, so 3 were just blank results, hence the date being what it was. Sometimes the obvious and just hard to see Link to comment https://forums.phpfreaks.com/topic/273007-rss-to-php-date-issue/#findComment-1404943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.