Zend_Feed-Introduction.xml 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.feed.introduction">
  4. <title>Introduction</title>
  5. <para>
  6. <classname>Zend_Feed</classname> provides functionality for consuming RSS and Atom feeds. It provides a
  7. natural syntax for accessing elements of feeds, feed attributes, and entry attributes.
  8. <classname>Zend_Feed</classname> also has extensive support for modifying feed and entry structure with the
  9. same natural syntax, and turning the result back into XML. In the future, this modification support
  10. could provide support for the Atom Publishing Protocol.
  11. </para>
  12. <para>
  13. Programmatically, <classname>Zend_Feed</classname> consists of a base <classname>Zend_Feed</classname> class, abstract
  14. <classname>Zend_Feed_Abstract</classname> and <classname>Zend_Feed_Entry_Abstract</classname> base classes for
  15. representing Feeds and Entries, specific implementations of feeds and entries for RSS and Atom, and
  16. a behind-the-scenes helper for making the natural syntax magic work.
  17. </para>
  18. <para>
  19. In the example below, we demonstrate a simple use case of retrieving an RSS feed and saving relevant
  20. portions of the feed data to a simple PHP array, which could then be used for printing the data, storing
  21. to a database, etc.
  22. </para>
  23. <note>
  24. <title>Be aware</title>
  25. <para>
  26. Many RSS feeds have different channel and item properties available. The RSS specification provides for
  27. many optional properties, so be aware of this when writing code to work with RSS data.
  28. </para>
  29. </note>
  30. <example id="zend.feed.introduction.example.rss">
  31. <title>Putting Zend_Feed to Work on RSS Feed Data</title>
  32. <programlisting role="php"><![CDATA[
  33. // Fetch the latest Slashdot headlines
  34. try {
  35. $slashdotRss =
  36. Zend_Feed::import('http://rss.slashdot.org/Slashdot/slashdot');
  37. } catch (Zend_Feed_Exception $e) {
  38. // feed import failed
  39. echo "Exception caught importing feed: {$e->getMessage()}\n";
  40. exit;
  41. }
  42. // Initialize the channel data array
  43. $channel = array(
  44. 'title' => $slashdotRss->title(),
  45. 'link' => $slashdotRss->link(),
  46. 'description' => $slashdotRss->description(),
  47. 'items' => array()
  48. );
  49. // Loop over each channel item and store relevant data
  50. foreach ($slashdotRss as $item) {
  51. $channel['items'][] = array(
  52. 'title' => $item->title(),
  53. 'link' => $item->link(),
  54. 'description' => $item->description()
  55. );
  56. }
  57. ]]></programlisting>
  58. </example>
  59. </sect1>
  60. <!--
  61. vim:se ts=4 sw=4 et:
  62. -->