anterior  
índice  
siguiente  
Updated 2012-10-02 - Version ZF 2.0.3

Importing Feeds

Zend\Feed enables developers to retrieve feeds very easily, by using Zend\Feader\Reader. If you know the URI of a feed, simply use the Zend\Feed\Reader\Reader::import() method:

1
$feed = Zend\Feed\Reader\Reader::import('http://feeds.example.com/feedName');

You can also use Zend\Feed\Reader\Reader to fetch the contents of a feed from a file or the contents of a PHP string variable:

1
2
3
4
5
// importing a feed from a text file
$feedFromFile = Zend\Feed\Reader\Reader::importFile('feed.xml');

// importing a feed from a PHP string variable
$feedFromPHP = Zend\Feed\Reader\Reader::importString($feedString);

In each of the examples above, an object of a class that extends Zend\Feed\Reader\Feed\AbstractFeed is returned upon success, depending on the type of the feed. If an RSS feed were retrieved via one of the import methods above, then a Zend\Feed\Reader\Feed\Rss object would be returned. On the other hand, if an Atom feed were imported, then a Zend\Feed\Reader\Feed\Atom object is returned. The import methods will also throw a Zend\Feed\Exception\Reader\RuntimeException object upon failure, such as an unreadable or malformed feed.

Dumping the contents of a feed

To dump the contents of a Zend\Feed\Reader\Feed\AbstractFeed instance, you may use the saveXml() method.

1
2
3
4
assert($feed instanceof Zend\Feed\Reader\Feed\AbstractFeed);

// dump the feed to standard output
print $feed->saveXml();
|

Contenidos

Tema anterior

Introduction

Próximo tema

Retrieving Feeds from Web Pages

Esta página

Nota: Es necesario estar conectado a tu cuenta GitHub para contribuir a la documentación.

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Importing Feeds on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.