comparison vendor/zendframework/zend-feed/doc/book/intro.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 # Introduction
2
3 `Zend\Feed` provides functionality for consuming RSS and Atom feeds. It provides
4 a natural syntax for accessing elements of feeds, feed attributes, and entry
5 attributes. `Zend\Feed` also has extensive support for modifying feed and entry
6 structure with the same natural syntax, and turning the result back into XML.
7 In the future, this modification support could provide support for the Atom
8 Publishing Protocol.
9
10 `Zend\Feed` consists of `Zend\Feed\Reader` for reading RSS and Atom feeds,
11 `Zend\Feed\Writer` for writing RSS and Atom feeds, and `Zend\Feed\PubSubHubbub`
12 for working with Hub servers. Furthermore, both `Zend\Feed\Reader` and
13 `Zend\Feed\Writer` support extensions which allows for working with additional
14 data in feeds, not covered in the core API but used in conjunction with RSS and
15 Atom feeds.
16
17 In the example below, we demonstrate a simple use case of retrieving an RSS feed
18 and saving relevant portions of the feed data to a simple PHP array, which could
19 then be used for printing the data, storing to a database, etc.
20
21 > ## RSS optional properties
22 >
23 > Many *RSS* feeds have different channel and item properties available. The
24 > *RSS* specification provides for many optional properties, so be aware of this
25 > when writing code to work with *RSS* data. `Zend\Feed` supports all optional
26 > properties of the core *RSS* and *Atom* specifications.
27
28 ## Reading RSS Feed Data
29
30 ```php
31 // Fetch the latest Slashdot headlines
32 try {
33 $slashdotRss =
34 Zend\Feed\Reader\Reader::import('http://rss.slashdot.org/Slashdot/slashdot');
35 } catch (Zend\Feed\Reader\Exception\RuntimeException $e) {
36 // feed import failed
37 echo "Exception caught importing feed: {$e->getMessage()}\n";
38 exit;
39 }
40
41 // Initialize the channel/feed data array
42 $channel = [
43 'title' => $slashdotRss->getTitle(),
44 'link' => $slashdotRss->getLink(),
45 'description' => $slashdotRss->getDescription(),
46 'items' => [],
47 ];
48
49 // Loop over each channel item/entry and store relevant data for each
50 foreach ($slashdotRss as $item) {
51 $channel['items'][] = [
52 'title' => $item->getTitle(),
53 'link' => $item->getLink(),
54 'description' => $item->getDescription(),
55 ];
56 }
57 ```
58
59 Your `$channel` array now contains the basic meta-information for the RSS
60 channel and all items that it contained. The process is identical for Atom
61 feeds since `Zend\Feed` provides a common feed API; i.e. all getters and
62 setters are the same regardless of feed format.