Chris@0: # Introduction Chris@0: Chris@0: `Zend\Feed` provides functionality for consuming RSS and Atom feeds. It provides Chris@0: a natural syntax for accessing elements of feeds, feed attributes, and entry Chris@0: attributes. `Zend\Feed` also has extensive support for modifying feed and entry Chris@0: structure with the same natural syntax, and turning the result back into XML. Chris@0: In the future, this modification support could provide support for the Atom Chris@0: Publishing Protocol. Chris@0: Chris@0: `Zend\Feed` consists of `Zend\Feed\Reader` for reading RSS and Atom feeds, Chris@0: `Zend\Feed\Writer` for writing RSS and Atom feeds, and `Zend\Feed\PubSubHubbub` Chris@0: for working with Hub servers. Furthermore, both `Zend\Feed\Reader` and Chris@0: `Zend\Feed\Writer` support extensions which allows for working with additional Chris@0: data in feeds, not covered in the core API but used in conjunction with RSS and Chris@0: Atom feeds. Chris@0: Chris@0: In the example below, we demonstrate a simple use case of retrieving an RSS feed Chris@0: and saving relevant portions of the feed data to a simple PHP array, which could Chris@0: then be used for printing the data, storing to a database, etc. Chris@0: Chris@0: > ## RSS optional properties Chris@0: > Chris@0: > Many *RSS* feeds have different channel and item properties available. The Chris@0: > *RSS* specification provides for many optional properties, so be aware of this Chris@0: > when writing code to work with *RSS* data. `Zend\Feed` supports all optional Chris@0: > properties of the core *RSS* and *Atom* specifications. Chris@0: Chris@0: ## Reading RSS Feed Data Chris@0: Chris@0: ```php Chris@0: // Fetch the latest Slashdot headlines Chris@0: try { Chris@0: $slashdotRss = Chris@0: Zend\Feed\Reader\Reader::import('http://rss.slashdot.org/Slashdot/slashdot'); Chris@0: } catch (Zend\Feed\Reader\Exception\RuntimeException $e) { Chris@0: // feed import failed Chris@0: echo "Exception caught importing feed: {$e->getMessage()}\n"; Chris@0: exit; Chris@0: } Chris@0: Chris@0: // Initialize the channel/feed data array Chris@0: $channel = [ Chris@0: 'title' => $slashdotRss->getTitle(), Chris@0: 'link' => $slashdotRss->getLink(), Chris@0: 'description' => $slashdotRss->getDescription(), Chris@0: 'items' => [], Chris@0: ]; Chris@0: Chris@0: // Loop over each channel item/entry and store relevant data for each Chris@0: foreach ($slashdotRss as $item) { Chris@0: $channel['items'][] = [ Chris@0: 'title' => $item->getTitle(), Chris@0: 'link' => $item->getLink(), Chris@0: 'description' => $item->getDescription(), Chris@0: ]; Chris@0: } Chris@0: ``` Chris@0: Chris@0: Your `$channel` array now contains the basic meta-information for the RSS Chris@0: channel and all items that it contained. The process is identical for Atom Chris@0: feeds since `Zend\Feed` provides a common feed API; i.e. all getters and Chris@0: setters are the same regardless of feed format.