Jump to content

RSS to PHP date issue


jarvis

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.