Last active
August 29, 2015 14:24
-
-
Save bepatrickdavid/1135e4828022b11fb076 to your computer and use it in GitHub Desktop.
PHP: Read RSS Feed with limit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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