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 Quote Link to comment 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 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.