Chris@0
|
1 # Feed Discovery from Web Pages
|
Chris@0
|
2
|
Chris@0
|
3 Web pages often contain `<link>` tags that refer to feeds with content relevant
|
Chris@0
|
4 to the particular page. `Zend\Feed\Reader\Reader` enables you to retrieve all
|
Chris@0
|
5 feeds referenced by a web page with one method call:
|
Chris@0
|
6
|
Chris@0
|
7 ```php
|
Chris@0
|
8 $feedLinks = Zend\Feed\Reader\Reader::findFeedLinks('http://www.example.com/news.html');
|
Chris@0
|
9 ```
|
Chris@0
|
10
|
Chris@0
|
11 > ## Finding feed links requires an HTTP client
|
Chris@0
|
12 >
|
Chris@0
|
13 > To find feed links, you will need to have an [HTTP client](zend.feed.http-clients)
|
Chris@0
|
14 > available.
|
Chris@0
|
15 >
|
Chris@0
|
16 > If you are not using zend-http, you will need to inject `Reader` with the HTTP
|
Chris@0
|
17 > client. See the [section on providing a client to Reader](http-clients.md#providing-a-client-to-reader).
|
Chris@0
|
18
|
Chris@0
|
19 Here the `findFeedLinks()` method returns a `Zend\Feed\Reader\FeedSet` object,
|
Chris@0
|
20 which is in turn a collection of other `Zend\Feed\Reader\FeedSet` objects, each
|
Chris@0
|
21 referenced by `<link>` tags on the `news.html` web page.
|
Chris@0
|
22 `Zend\Feed\Reader\Reader` will throw a
|
Chris@0
|
23 `Zend\Feed\Reader\Exception\RuntimeException` upon failure, such as an HTTP
|
Chris@0
|
24 404 response code or a malformed feed.
|
Chris@0
|
25
|
Chris@0
|
26 You can examine all feed links located by iterating across the collection:
|
Chris@0
|
27
|
Chris@0
|
28 ```php
|
Chris@0
|
29 $rssFeed = null;
|
Chris@0
|
30 $feedLinks = Zend\Feed\Reader\Reader::findFeedLinks('http://www.example.com/news.html');
|
Chris@0
|
31 foreach ($feedLinks as $link) {
|
Chris@0
|
32 if (stripos($link['type'], 'application/rss+xml') !== false) {
|
Chris@0
|
33 $rssFeed = $link['href'];
|
Chris@0
|
34 break;
|
Chris@0
|
35 }
|
Chris@0
|
36 ```
|
Chris@0
|
37
|
Chris@0
|
38 Each `Zend\Feed\Reader\FeedSet` object will expose the `rel`, `href`, `type`,
|
Chris@0
|
39 and `title` properties of detected links for all RSS, Atom, or RDF feeds. You
|
Chris@0
|
40 can always select the first encountered link of each type by using a shortcut:
|
Chris@0
|
41 the first encountered link of a given type is assigned to a property named after
|
Chris@0
|
42 the feed type.
|
Chris@0
|
43
|
Chris@0
|
44 ```php
|
Chris@0
|
45 $rssFeed = null;
|
Chris@0
|
46 $feedLinks = Zend\Feed\Reader\Reader::findFeedLinks('http://www.example.com/news.html');
|
Chris@0
|
47 $firstAtomFeed = $feedLinks->atom;
|
Chris@0
|
48 ```
|