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