Jan 21 2011

Zend Framework: Modifying rss feeds using Zend_Feed

On the previous post, i introducing the “Consuming feeds using Zend_Feed” thematic, today i will try to explain how we can change a RSS feed and return it after the changes.

We will be acting as a proxy for the RSS feed. I will parse all feed items and add a “TEST: ” string before my title and add a tracking parameter to each link “?source=feed”.

$feedUrl = "http://blog.josedasilva.net/feed/";
// Lets import the feed
try {
     $feed   =   Zend_Feed::import($feedUrl);
} catch (Zend_Feed_Exception $e) {
     echo 'Exception found: '.$e->getMessage();
// Iterating over the feed and performing changes
foreach($feed as $idx=>$entry) {
    $entry->title       =       "TEST: ".(string)$entry->title;
    $entry->link        .=      "?source=feed";
// Saving the feed and capturing the feed output
$feedContent =  $feed->saveXML();
echo $feedContent;

The retaining code line on this quick example is:

This will return a rebuild version of the feed object (not the original one).

Why bother and why should i want to modify a feed

A practical approach on modifying feed entries is the shown below, adding parameters into your links so that you can analyse it afterwards. If you use feed burner, you just need to change the feed endpoint to your script path, for the modified feed, and you are ready to go.

As you can see consuming and modifying feeds using Zend_Feed is extremely simple.

One comment on “Zend Framework: Modifying rss feeds using Zend_Feed

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>