Displaying RSS Items using PHP
- 5 October, 2011 -
- PHP -
- Tags : Code Snippets, PHP, RSS
- 0 Comments
This script parses an RSS file and displays the items in a list. The script should be encased by a ordered or unordered list tag
<?php
$rss_url = "http://feedity.com/rss.aspx/google-com/UVRSWlpQ";
if (!$rss_data = @file_get_contents($rss_url)) {
echo "<li>Seems we're having a hard time finding that RSS, it'll be back soon!</li>";
} else {
$rss_xml = SimpleXML_Load_String($rss_data);
$channel_title = $rss_xml->channel->title;
$channel_link = $rss_xml->channel->link;
foreach ($rss_xml->channel->item as $item) {
$item_title = $item->title;
$item_link = $item->link;
echo "<li>$item_title - <a href=\"$item_link\" target=\"_blank\">view article</a></li>\n";
}
}
?>