Skip to content

Instantly share code, notes, and snippets.

@rozzy
Created June 22, 2013 12:06
Show Gist options
  • Save rozzy/5840654 to your computer and use it in GitHub Desktop.
Save rozzy/5840654 to your computer and use it in GitHub Desktop.
Get 5 last feed articles (html-anchor style)
<?
function getFeed($feed_url) {
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
$feed = array();
$str = "";
foreach($x->channel->item as $entry) {
if (count($feed) < 5) {
$f = "<li><a href='$entry->link' title='$entry->title'>$entry->title</a></li>";
array_push($feed, $f);
$str .= $f;
}
}
return (object) array('array' => $feed, 'string' => $str);
}
echo getFeed('http://ilyacoder.ru/rss/')->string;
@lukateras
Copy link

Not bad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment