Last active
December 31, 2015 23:29
-
-
Save Boztown/8060860 to your computer and use it in GitHub Desktop.
Grab and RSS Feed with PHP.
This file contains hidden or 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
<?php getFeed("http://ryanbosinger.com/blog/feed", 3); ?> |
This file contains hidden or 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
<?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