Skip to content

Zend Framework : Consuming feeds using Zend_Feed

Using Zend Framework Zend_Feed is extremely simple to iteract or even modify a rss feed. Let’s give a quick look into consuming feeds.


// Iterating over the feed
foreach($feed as $index=>$entry) {
    echo (string)$entry->title."\n";
    echo (string)$entry->description."\n";

// Playing around with the complete feed and outputting it.

$feedContent =   ob_get_contents(); // feed content stored on this variable

echo $feedContent;

Some comments

$feed = Zend_Feed::import($feedUrl);
This will import the feed from a feed url and return an object of a class that extends Zend_Feed_Abstract if the importation has success and throws a Zend_Feed_Exception if it’s not.

foreach($feed as $index=>$entry)

We may iterate over a feed object using a foreach, on my example you will access each feed entry on the $entry variable.

$entry var will be a Zend_Feed_Entry_Rss or a Zend_Feed_Entry_Atom object instance, depending on the feed type you have imported. Each $entry attribute (title, description , …) will be an Zend_Feed_Element object instance, although you can simply to access the attribute value by forcing a cast into (string).

Now, this is a quick look into reading data from a RSS feed using Zend_Feed, on the next post on this series i will give a quick insights on modifying the feed and returning the result.

Published inRandom Thoughts

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *