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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.