comparison vendor/zendframework/zend-feed/doc/book/importing.md @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 # Importing Feeds
2
3 `Zend\Feed` enables developers to retrieve feeds via `Zend\Feader\Reader`. If
4 you know the URI of a feed, use the `Zend\Feed\Reader\Reader::import()` method
5 to consume it:
6
7 ```php
8 $feed = Zend\Feed\Reader\Reader::import('http://feeds.example.com/feedName');
9 ```
10
11 > ## Importing requires an HTTP client
12 >
13 > To import a feed, you will need to have an [HTTP client](zend.feed.http-clients)
14 > available.
15 >
16 > If you are not using zend-http, you will need to inject `Reader` with the HTTP
17 > client. See the [section on providing a client to Reader](http-clients.md#providing-a-client-to-reader).
18
19 You can also use `Zend\Feed\Reader\Reader` to fetch the contents of a feed from
20 a file or the contents of a PHP string variable:
21
22 ```php
23 // importing a feed from a text file
24 $feedFromFile = Zend\Feed\Reader\Reader::importFile('feed.xml');
25
26 // importing a feed from a PHP string variable
27 $feedFromPHP = Zend\Feed\Reader\Reader::importString($feedString);
28 ```
29
30 In each of the examples above, an object of a class that extends
31 `Zend\Feed\Reader\Feed\AbstractFeed` is returned upon success, depending on the
32 type of the feed. If an RSS feed were retrieved via one of the import methods
33 above, then a `Zend\Feed\Reader\Feed\Rss` object would be returned. On the other
34 hand, if an Atom feed were imported, then a `Zend\Feed\Reader\Feed\Atom` object
35 is returned. The import methods will also throw a
36 `Zend\Feed\Exception\Reader\RuntimeException` object upon failure, such as an
37 unreadable or malformed feed.
38
39 ## Dumping the contents of a feed
40
41 To dump the contents of a `Zend\Feed\Reader\Feed\AbstractFeed` instance, you may
42 use the `saveXml()` method.
43
44 ```php
45 assert($feed instanceof Zend\Feed\Reader\Feed\AbstractFeed);
46
47 // dump the feed to standard output
48 print $feed->saveXml();
49 ```