Zend_Feed-Introduction.xml 2.8 KB

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