
Posts Tagged ‘web development’
PHP RSS Feed Reader
September 8th, 2009 - Be the First Comment!
I decided to add some RSS feeds to the home page area of my site. This is relatively easy to do, especially with MagpieRSS. Here is an example for this blogs RSS:
<?php
// Limit the number of items to display
$rssItemsToDisplay = 5;
// Find the rss_fetch scrip in the MagpieRSS directory
require_once 'include/magpierss/rss_fetch.inc';
// Specify the location of the RSS feed
$uri = 'http://feeds.feedburner.com/BrokenBytes?format=xml';
if ($rss = fetch_rss( $uri )) {
// This limits the number of items to display using the variable declared earlier
$items = array_slice($rss->items, 0, $rssItemsToDisplay);
// Loop through the RSS items
foreach ($items as $item) {
$url = $item['link'];
$title = htmlspecialchars($item['title']);
$date = $item['pubdate'];
if(!$date) {
$date = $item['dc']['date'];
}
print '<p>';
print '<div class="rss_title">'."\n";
if ($date) {
print '<span class="rss_date">'."\n";
// cut off + or - of date
print substr($date, 0, 25);
print '</span><br />';
}
print '<a href="'.$url.'">'.$title.'</a>'."\n";
print '</div>\n\n';
print '</p>\n\n';
}
}
?>
As you can see it is pretty simple! Now go out and add your favorite RSS feeds into you website!
[ Tags ]: feed reader, MagpieRSS, php, rss, web development, webdev
[ Category ]: programming




