Using Magpie to Parse RSS Feeds

This FAQ is intended for Birdhouse web developers only.

The Magpie RSS parser is installed on Birdhouse, so it’s easy to include the output of other sites’ RSS feeds on your site. Just create a PHP page in your public_html directory which includes the code below, replacing the $url variable with the address of the feed you want to display:


<?php
// Magpie installed server wide, so can invoke with:
require_once('magpierss/rss_fetch.inc');

// URL of RSS feed:
$url="http://birdhouse.org/blog/index.xml";

$rss = fetch_rss($url);

echo "Channel Title: " . $rss->channel['title'] . "<p>";
echo "<ul>";
foreach ($rss->items as $item) {
	$href = $item['link'];
	$title = $item['title'];
	echo "<li><a href=\"$href\">$title</a></li>";
}
echo "</ul>";
?>

Strongly recommended: Magpie will try to cache its results, so that subsequent results will be nice and fast. Caching will also help prevent you from being banned by servers for requesting RSS feeds too often. You really should run Magpie with caching enabled. Just create a directory called “cache” in the same directory where the script lives, and make it writable by the webserver. You can do this quickly yourself by setting the cache directory to be world-writable:

chmod 777 cache

However, it’s not the best idea to make anything world-writable. After testing, ask Birdhouse to set up your cache directory more securely.

Please see the Magpie FAQ for more information.

Return to FAQs