Introduction to Zend Framework

 Learning Zend Framework


 Zend Framework Reference

  •  Zend_Gdata
  •  Zend_Http
  •  Zend_InfoCard
  •  Zend_Json
  •  Zend_Layout
  •  Zend_Ldap
  •  Zend_Loader
  •  Zend_Locale
  •  Zend_Log
  •  Zend_Mail
  •  Zend_Markup
  •  Zend_Measure
  •  Zend_Memory
  •  Zend_Mime
  •  Zend_Navigation
  •  Zend_Oauth
  •  Zend_OpenId
  •  Zend_Paginator
  •  Zend_Pdf
  •  Zend_ProgressBar
  •  Zend_Queue
  •  Zend_Reflection
  •  Zend_Registry
  •  Zend_Rest

  •  Zend_Search_Lucene
  •  Zend_Serializer
  •  Zend_Server
  •  Zend_Service
  •  Zend_Session
  •  Zend_Soap
  •  Zend_Tag
  •  Zend_Test
  •  Zend_Text
  •  Zend_TimeSync
  •  Zend_Tool
  •  Zend_Tool_Framework
  •  Zend_Tool_Project
  •  Zend_Translate
  •  Zend_Uri
  •  Zend_Validate
  •  Zend_Version
  •  Zend_View
  •  Zend_Wildfire
  •  Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Update 2011-11-16 - Revision 24438 - Version ZF 1.11.x

    32.4. Consuming an RSS Feed

    Reading an RSS feed is as simple as instantiating a Zend_Feed_Rss object with the URL of the feed:

    $channel = new Zend_Feed_Rss('');

    If any errors occur fetching the feed, a Zend_Feed_Exception will be thrown.

    Once you have a feed object, you can access any of the standard RSS "channel" properties directly on the object:

    echo $channel->title();

    Note the function syntax. Zend_Feed uses a convention of treating properties as XML object if they are requested with variable "getter" syntax ($obj->property) and as strings if they are access with method syntax ($obj->property()). This enables access to the full text of any individual node while still allowing full access to all children.

    If channel properties have attributes, they are accessible using PHP's array syntax:

    echo $channel->category['domain'];

    Since XML attributes cannot have children, method syntax is not necessary for accessing attribute values.

    Most commonly you'll want to loop through the feed and do something with its entries. Zend_Feed_Abstract implements PHP's Iterator interface, so printing all titles of articles in a channel is just a matter of:

    foreach ($channel as $item) {
    $item->title() . "\n";

    If you are not familiar with RSS, here are the standard elements you can expect to be available in an RSS channel and in individual RSS items (entries).

    Required channel elements:

    • title - The name of the channel

    • link - The URL of the web site corresponding to the channel

    • description - A sentence or several describing the channel

    Common optional channel elements:

    • pubDate - The publication date of this set of content, in RFC 822 date format

    • language - The language the channel is written in

    • category - One or more (specified by multiple tags) categories the channel belongs to

    RSS <item> elements do not have any strictly required elements. However, either title or description must be present.

    Common item elements:

    • title - The title of the item

    • link - The URL of the item

    • description - A synopsis of the item

    • author - The author's email address

    • category - One more categories that the item belongs to

    • comments - URL of comments relating to this item

    • pubDate - The date the item was published, in RFC 822 date format

    In your code you can always test to see if an element is non-empty with:

    if ($item->propname()) {
    // ... proceed.

    If you use $item->propname instead, you will always get an empty object which will evaluate to TRUE, so your check will fail.

    For further information, the official RSS 2.0 specification is available at:

    digg delicious meneame google twitter technorati facebook