Note that in our example we use the send() method which sets the content type of the HTTP header string for us to something like this: Content-Type: text/xml; charset=UTF-8 If we were using the feed in some other way we could just use the following to get the XML string without the HTTP headers: $feed->saveXml() Figure 11.3 The feed we produced as it appears in the Firefox web browser together with the XML source. In figure 11.3 we can see that Firefox recognises this as a web feed, shows its parsed content and asks if we??™d like to subscribe to it through its Live Bookmarks. It should be noted, however, that the feed we??™ve produced is a little too minimal and would likely need further elements added for it to work with other readers and aggregators. We have kept it simple for the sake of clarity. Licensed to Menshu You Zend Framework in Action (Ch01) Manning Publications Co. 20 11.2.2 Consuming a feed Earlier in this chapter we gave an example of the consumption of web feeds retrieved from the websites of listings in an online directory. In that particular case each listing had the URL of its feed stored along with its other data. If that site had been built using Zend Framework storing the specific feed URL would have been unnecessary as Zend_Feed is able to parse any HTML page searching for the same link elements that modern browsers use to indicate the presence of a feed: title="Places RSS Feed" href="/feed/index/format/rss/" /> title="Places Atom Feed" href="/feed/index/format/atom/" /> All that is required is a single line of code: $feedArray = Zend_Feed::findFeeds('http://places/'); In the current case we do know the URL for the feed we produced earlier and the code to consume that feed is straightforward as it imports directly from the URL: $this->view->feed = Zend_Feed::import('http://places/feed/index/format/rss/'); The elements of that feed could then be presented in a view like so:
While we??™re covering the methods of consuming feeds it would be remiss not to mention the remaining methods which include importing from a text file: $cachedFeed = Zend_Feed::importFile('cache/feed.