Friday, June 18, 2004

Parsing RSS in PHP

I found this pretty cool project to display RSS feeds in PHP scripts. It is called Magpie RSS. It parses the rss feed, and then allows PHP to display it as you want.

It looks like it supports RSS 0.9 through RSS 1.0. It also parses RSS 1.0's modules, RSS 2.0, and Atom

Here is an example that I created of a php script parsing this blog.

There is another example of this that is availabe with PEAR. But it doesn't appear that XML_RSS has been updated as recently.




Here is the php from my example:


$url = "http://www.westbrooks.org/blog/rss.php?blogId=2&profile=rss20";
print "<h1>RSS parsing with mag pie</h1>n";
include ( "rss_fetch.inc" );
$rss = fetch_rss( $url );
echo "<h2><a href="" . $rss->channel['link'] . "">" . $rss->channel['title'] . "</a></h2>";
echo $rss->channel['description'];
echo "<p>";
echo "<ul>";
foreach ($rss->items as $item) {
$href = $item['link'];
$title = $item['title'];
$description = $item['description'];
echo "<li><a href=$href>$title</a></li>";
}
echo "</ul>";

No comments:

Post a Comment

Unlocking Raspberry Pi Potential: Navigating Network Booting Challenges for Enhanced Performance and Reliability

I've set up several Raspberry Pis around our house for various projects, but one recurring challenge is the potential for SD card failur...