Zend_Feed-Introduction.xml 2.8 KB

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