Zend Framework - Zend_Feed


Zend_Feed is used to consume RSS and Atom feeds. It is a simple yet powerful module in Zend Framework, to provide programmers a natural syntax for accessing elements of feeds, feed attributes, and entry attributes. Besides that it also has an extensive support to change feed and entry structure, and return new result back into XML, a recommended format to share structured data across different information systems, especially via the internet.

Now I will show you a simple code to access my very own feeds from my blog, since I am using Feedburner, my RSS feeds address will be at http://feeds.feedburner.com/radicalfix:

<?php
 
require_once 'Zend/Feed.php';
 
// a list of feeds you want to import 
$feeds = array ('http://feeds.feedburner.com/radicalfix');
 
foreach($feeds as $feed){
	// import feeds
	$channel = Zend_Feed::import($feed);
 
	$channelTitle =  $channel->title(); // the channel title 
	echo $channelTitle."\n\n"; // print the channel title
 
	/* for this example I will loop through the 
	 * requires RSS channel elements (title, link, decription)
	 * many optional elements are available please refer to 
	 * the latest RRS 2.0 Specification (http://cyber.law.harvard.edu/rss/rss.html) */ 
	foreach($channel->items as $item){
		$itemTitle = $item->title(); // the title of the feed
		$itemDesc = $item->description(); // the description of the feed
		$itemLink = $item->link(); // the link of the feed
 
		echo "\t".$itemTitle."\n\t".$itemDesc."\n\t".$itemLink."\n\n";
	}
}
 
?>

I will show you how to modify the RSS for the next few posts.

References:
RSS 2.0 specification: RSS 2.0

Comments (1) left to “Zend Framework - Zend_Feed”

  1. PHP by example - Simple XML Parsing with SimpleXML | Kelvin's Blog wrote:

    […] There is a better way to process the RSS feeds, Read my previous post about Zend_Feed. […]

Post a Comment

*Required
*Required (Never published)