Skip to content

Instantly share code, notes, and snippets.

@Boztown
Last active December 31, 2015 23:29
Show Gist options
  • Save Boztown/8060860 to your computer and use it in GitHub Desktop.
Save Boztown/8060860 to your computer and use it in GitHub Desktop.
Grab and RSS Feed with PHP.
<?php getFeed("http://ryanbosinger.com/blog/feed", 3); ?>
<?php
function getFeed($feed_url, $posts_to_show) {
try
{
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
echo "<ul>";
$i = 0;
while ($i < $posts_to_show){
echo "<li><a href=\"" . $x->channel->item[$i]->link . "\" title=\"" . $x->channel->item[$i]->title . "\" target=\"_blank\">" . $x->channel->item[$i]->title . "</a></li>";
$i++;
}
echo "</ul>";
}
catch (Exception $e)
{
echo "<p>The blog feed doesn't seem to be available at the moment...</p>";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment