Thursday, February 05, 2009

Magpie RSS - PHP RSS Parser

I like the Magpie RSS - PHP RSS Parser, a "XML-based RSS parser in PHP. Supports most RSS versions including Userland RSS and RSS 1.0. Supports modules and namespaces magpierss.sourceforge.net/"

I used it to parse the Hollywood-USA.mobi Showbiz News page at http://hollywood-usa.mobi/news.php

The news source is the movie industry standard The Hollywood Reporter RSS news feed.

However, note when you look at the source file of the feed itself at http://feeds2.feedburner.com/thr/news that the RSS feed authors added html tags and other conten of no interest to me. So I used 'explode' in this fragment of PHP code below to trim the string:
require_once('magpie/rss_fetch.inc');
//
$url = 'http://feeds.feedburner.com/thr/news/';
$rss = fetch_rss( $url );
//
foreach ($rss->items as $item) {
$title = $item['title'];
$description = $item['description'];
$pieces = explode("<", $description);
print "$title ".$pieces[0]."";

In earlier attempts I was working with 'lastRSS 0.9.1' "Simple yet powerfull [sic] PHP class to parse RSS files. by Vojtech Semecky, webmaster @ oslab . net with Latest version, features, manual and examples: http://lastrss.oslab.net/"

No comments: