Skip to content

Instantly share code, notes, and snippets.

@bepatrickdavid
Last active August 29, 2015 14:24
Show Gist options
  • Save bepatrickdavid/1135e4828022b11fb076 to your computer and use it in GitHub Desktop.
Save bepatrickdavid/1135e4828022b11fb076 to your computer and use it in GitHub Desktop.
PHP: Read RSS Feed with limit
function getFeed($feed_url, $limit) {
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
echo "<ul>";
$count = $limit;
foreach($x->channel->item as $entry) {
$timestamp = strtotime($entry->pubDate);
$new_date = date('j/m/Y - G:i',$timestamp);
echo "<li><a href='$entry->link' title='$entry->title'><span class='widget-date'>". $new_date ."</span><br>" . $entry->title . "</a></li>";
if($count <= 1)
break;
$count--;
}
echo "</ul>";
}
/* Use */
<?php getFeed("http://www.prova.it/feed/",2); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment