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"

I used it to parse the Showbiz News page at

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 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:
$url = '';
$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:"

No comments: