Chris@0: # Importing Feeds Chris@0: Chris@0: `Zend\Feed` enables developers to retrieve feeds via `Zend\Feader\Reader`. If Chris@0: you know the URI of a feed, use the `Zend\Feed\Reader\Reader::import()` method Chris@0: to consume it: Chris@0: Chris@0: ```php Chris@0: $feed = Zend\Feed\Reader\Reader::import('http://feeds.example.com/feedName'); Chris@0: ``` Chris@0: Chris@0: > ## Importing requires an HTTP client Chris@0: > Chris@0: > To import a feed, you will need to have an [HTTP client](zend.feed.http-clients) Chris@0: > available. Chris@0: > Chris@0: > If you are not using zend-http, you will need to inject `Reader` with the HTTP Chris@0: > client. See the [section on providing a client to Reader](http-clients.md#providing-a-client-to-reader). Chris@0: Chris@0: You can also use `Zend\Feed\Reader\Reader` to fetch the contents of a feed from Chris@0: a file or the contents of a PHP string variable: Chris@0: Chris@0: ```php Chris@0: // importing a feed from a text file Chris@0: $feedFromFile = Zend\Feed\Reader\Reader::importFile('feed.xml'); Chris@0: Chris@0: // importing a feed from a PHP string variable Chris@0: $feedFromPHP = Zend\Feed\Reader\Reader::importString($feedString); Chris@0: ``` Chris@0: Chris@0: In each of the examples above, an object of a class that extends Chris@0: `Zend\Feed\Reader\Feed\AbstractFeed` is returned upon success, depending on the Chris@0: type of the feed. If an RSS feed were retrieved via one of the import methods Chris@0: above, then a `Zend\Feed\Reader\Feed\Rss` object would be returned. On the other Chris@0: hand, if an Atom feed were imported, then a `Zend\Feed\Reader\Feed\Atom` object Chris@0: is returned. The import methods will also throw a Chris@0: `Zend\Feed\Exception\Reader\RuntimeException` object upon failure, such as an Chris@0: unreadable or malformed feed. Chris@0: Chris@0: ## Dumping the contents of a feed Chris@0: Chris@0: To dump the contents of a `Zend\Feed\Reader\Feed\AbstractFeed` instance, you may Chris@0: use the `saveXml()` method. Chris@0: Chris@0: ```php Chris@0: assert($feed instanceof Zend\Feed\Reader\Feed\AbstractFeed); Chris@0: Chris@0: // dump the feed to standard output Chris@0: print $feed->saveXml(); Chris@0: ```