title: getting RSS feeds on website
body: <p>I had this code that I wrote last year and it returns RSS feeds for some term I enter:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;form name="form" action="search.php" method="get"&gt;
    &lt;input type="text" name="q" /&gt;
    &lt;input type="submit" name="Submit" value="Search" /&gt;
  &lt;/form&gt;
  
  &lt;?php
  
  
  require_once "RSS.php";
  
  
  // want to parse the $row[1] variable to get out words, make new string with a + instead of spaces
  
  
  $college = "college";
  
  $collegelen= strlen($college);
  
  for($i = 0; $i &lt; $collegelen; $i++){
  if ($college{$i} == " ")
  {$spaced = $spaced . "+";}
  else
  {$spaced = $spaced . $college{$i};}
  }
  
  echo("Yahoo! News RSS");
  
  $rss_yahoo =&amp; new XML_RSS("http://news.search.yahoo.com/news/rss?p=" . $spaced . "&amp;ei=UTF-8&amp;fl=0&amp;x=wrt");
  $rss_yahoo-&gt;parse();
  
  foreach ($rss_yahoo-&gt;getItems() as $item) {
    echo "&lt;li&gt;&lt;a href=\"" . $item['link'] . "\"&gt;" . $item['title'] . "&lt;/a&gt;&lt;/li&gt;&lt;br&gt;";
  //echo $item['pubDate'] ."&lt;br&gt;";
    echo $item['description'] . "&lt;br&gt;&lt;br&gt;\n"; }
  
  //echo("Google RSS");
  
  //$rss_google =&amp; new XML_RSS("http://news.google.com/news?hl=en&amp;ned=us&amp;q=" . $spaced . "&amp;ie=UTF-8&amp;nolr=1&amp;output=rss");
  //$rss_google-&gt;parse();
  
  //foreach ($rss_google-&gt;getItems() as $item) {
  //  echo "&lt;li&gt;&lt;a href=\"" . $item['link'] . "\"&gt;" . $item['title'] . "&lt;/a&gt;&lt;/li&gt;&lt;br&gt;";
  //  echo $item['description'] . "&lt;br&gt;&lt;br&gt;\n"; }
  
  echo("Google RSS");
  
  $rss_google =&amp; new XML_RSS("http://news.google.com/news?hl=en&amp;ned=us&amp;q=" . $spaced . "&amp;ie=UTF-8&amp;nolr=1&amp;output=rss");
  $rss_google-&gt;parse();
  
  foreach ($rss_google-&gt;getItems() as $item) {
    echo "&lt;li&gt;&lt;a href=\"" . $item['link'] . "\"&gt;" . $item['title'] . "&lt;/a&gt;&lt;/li&gt;&lt;br&gt;";
  - Hide quoted text -
   "&lt;br&gt;&lt;br&gt;\n"; }
  
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>RSS.php</p>
  
  <pre><code>&lt;?php
  // vim: set expandtab tabstop=4 shiftwidth=4 fdm=marker:
  // +----------------------------------------------------------------------+
  // | PHP Version 4                                                        |
  // +----------------------------------------------------------------------+
  // | Copyright (c) 1997-2003 The PHP Group                                |
  // +----------------------------------------------------------------------+
  // | This source file is subject to version 2.02 of the PHP license,      |
  // | that is bundled with this package in the file LICENSE, and is        |
  // | available at through the world-wide-web at                           |
  // | http://www.php.net/license/2_02.txt.                                 |
  // | If you did not receive a copy of the PHP license and are unable to   |
  // | obtain it through the world-wide-web, please send a note to          |
  // | license@php.net so we can mail you a copy immediately.               |
  // +----------------------------------------------------------------------+
  // | Authors: Martin Jansen &lt;mj@php.net&gt;                                  |
  // |                                                                      |
  // +----------------------------------------------------------------------+
  //
  // $Id: RSS.php,v 1.28 2006/09/14 08:40:05 clay Exp $
  //
  
  require_once 'Parser.php';
  
  /**
  * RSS parser class.
  *
  * This class is a parser for Resource Description Framework (RDF) Site
  * Summary (RSS) documents. For more information on RSS see the
  * website of the RSS working group (http://www.purl.org/rss/).
  *
  * @author Martin Jansen &lt;mj@php.net&gt;
  * @version $Revision: 1.28 $
  * @access  public
  */
  class XML_RSS extends XML_Parser
  {
      // {{{ properties
  
      /**
       * @var string
       */
      var $insideTag = '';
  
      /**
       * @var array
       */
      var $insideTagStack = array();
  
      /**
       * @var string
       */
      var $activeTag = '';
  
      /**
       * @var array
       */
      var $channel = array();
  
      /**
       * @var array
       */
      var $items = array();
  
      /**
       * @var array
       */
      var $item = array();
  
      /**
       * @var array
       */
      var $image = array();
  
      /**
       * @var array
       */
      var $textinput = array();
  
      /**
       * @var array
       */
      var $textinputs = array();
  
      /**
       * @var array
       */
      var $attribs;
  
      /**
       * @var array
       */
      var $parentTags = array('CHANNEL', 'ITEM', 'IMAGE', 'TEXTINPUT');
  
      /**
       * @var array
       */
      var $channelTags = array('TITLE', 'LINK', 'DESCRIPTION', 'IMAGE',
                                'ITEMS', 'TEXTINPUT', 'LANGUAGE', 'COPYRIGHT',
                                'MANAGINGEditor', 'WEBMASTER', 'PUBDATE', 'LASTBUILDDATE',
                                'CATEGORY', 'GENERATOR', 'DOCS', 'CLOUD', 'TTL',
                                'RATING');
  
      /**
       * @var array
       */
      var $itemTags = array('TITLE', 'LINK', 'DESCRIPTION', 'PUBDATE', 'AUTHOR', 'CATEGORY',
                            'COMMENTS', 'ENCLOSURE', 'GUID', 'PUBDATE', 'SOURCE',
                            'CONTENT:ENCODED');
  
      /**
       * @var array
       */
      var $imageTags = array('TITLE', 'URL', 'LINK', 'WIDTH', 'HEIGHT');
  
  
      var $textinputTags = array('TITLE', 'DESCRIPTION', 'NAME', 'LINK');
  
      /**
       * List of allowed module tags
       *
       * Currently supported:
       *
       *   Dublin Core Metadata
       *   blogChannel RSS module
       *   CreativeCommons
       *   Content
       *   Syndication
       *   Trackback
       *   GeoCoding
       *   Media
       *   iTunes
       *
       * @var array
       */
      var $moduleTags = array('DC:TITLE', 'DC:CREATOR', 'DC:SUBJECT', 'DC:DESCRIPTION',
                              'DC:PUBLISHER', 'DC:CONTRIBUTOR', 'DC:DATE', 'DC:TYPE',
                              'DC:FORMAT', 'DC:IDENTIFIER', 'DC:SOURCE', 'DC:LANGUAGE',
                              'DC:RELATION', 'DC:COVERAGE', 'DC:RIGHTS',
                              'BLOGCHANNEL:BLOGROLL', 'BLOGCHANNEL:MYSUBSCRIPTIONS',
                              'BLOGCHANNEL:BLINK', 'BLOGCHANNEL:CHANGES',
                              'CREATIVECOMMONS:LICENSE', 'CC:LICENSE', 'CONTENT:ENCODED',
                              'SY:UPDATEPERIOD', 'SY:UPDATEFREQUENCY', 'SY:UPDATEBASE',
                              'TRACKBACK:PING', 'GEO:LAT', 'GEO:LONG',
                              'MEDIA:GROUP', 'MEDIA:CONTENT', 'MEDIA:ADULT',
                              'MEDIA:RATING', 'MEDIA:TITLE', 'MEDIA:DESCRIPTION',
                              'MEDIA:KEYWORDS', 'MEDIA:THUMBNAIL', 'MEDIA:CATEGORY',
                              'MEDIA:HASH', 'MEDIA:PLAYER', 'MEDIA:CREDIT',
                              'MEDIA:COPYRIGHT', 'MEDIA:TEXT', 'MEDIA:RESTRICTION',
                              'ITUNES:AUTHOR', 'ITUNES:BLOCK', 'ITUNES:CATEGORY',
                              'ITUNES:DURATION', 'ITUNES:EXPLICIT', 'ITUNES:IMAGE',
                              'ITUNES:KEYWORDS', 'ITUNES:NEW-FEED-URL', 'ITUNES:OWNER',
                              'ITUNES:PUBDATE', 'ITUNES:SUBTITLE', 'ITUNES:SUMMARY'
                              );
  
      /**
       * @var array
       */
      var $last = array();
  
      // }}}
      // {{{ Constructor
  
      /**
       * Constructor
       *
       * @access public
       * @param mixed File pointer, name of the RSS file, or an RSS string.
       * @param string  Source charset encoding, use null (default) to use
       *                default encoding (ISO-8859-1)
       * @param string  Target charset encoding, use null (default) to use
       *                default encoding (ISO-8859-1)
       * @return void
       */
      function XML_RSS($handle = '', $srcenc = null, $tgtenc = null)
      {
          if ($srcenc === null &amp;&amp; $tgtenc === null) {
              $this-&gt;XML_Parser();
          } else {
              $this-&gt;XML_Parser($srcenc, 'event', $tgtenc);
          }
  
          $this-&gt;setInput($handle);
  
          if ($handle == '') {
              $this-&gt;raiseError('No input passed.');
          }
      }
  
      // }}}
      // {{{ startHandler()
  
      /**
       * Start element handler for XML parser
       *
       * @access private
       * @param  object XML parser object
       * @param  string XML element
       * @param  array  Attributes of XML tag
       * @return void
       */
      function startHandler($parser, $element, $attribs)
      {
          if (substr($element, 0, 4) == "RSS:") {
              $element = substr($element, 4);
          }
  
          switch ($element) {
              case 'CHANNEL':
              case 'ITEM':
              case 'IMAGE':
              case 'TEXTINPUT':
                  $this-&gt;insideTag = $element;
                  array_push($this-&gt;insideTagStack, $element);
                  break;
  
              case 'ENCLOSURE' :
                  $this-&gt;attribs = $attribs;
                  break;
  
              default:
                  $this-&gt;activeTag = $element;
          }
      }
  
      // }}}
      // {{{ endHandler()
  
      /**
       * End element handler for XML parser
       *
       * If the end of &lt;item&gt;, &lt;channel&gt;, &lt;image&gt; or &lt;textinput&gt;
       * is reached, this method updates the structure array
       * $this-&gt;struct[] and adds the field "type" to this array,
       * that defines the type of the current field.
       *
       * @access private
       * @param  object XML parser object
       * @param  string
       * @return void
       */
      function endHandler($parser, $element)
      {
          if (substr($element, 0, 4) == "RSS:") {
              $element = substr($element, 4);
          }
  
          if ($element == $this-&gt;insideTag) {
              array_pop($this-&gt;insideTagStack);
              $this-&gt;insideTag = end($this-&gt;insideTagStack);
  
              $this-&gt;struct[] = array_merge(array('type' =&gt; strtolower($element)),
                                            $this-&gt;last);
          }
  
          if ($element == 'ITEM') {
              $this-&gt;items[] = $this-&gt;item;
              $this-&gt;item = '';
          }
  
          if ($element == 'IMAGE') {
              $this-&gt;images[] = $this-&gt;image;
              $this-&gt;image = '';
          }
  
          if ($element == 'TEXTINPUT') {
              $this-&gt;textinputs = $this-&gt;textinput;
              $this-&gt;textinput = '';
          }
  
          if ($element == 'ENCLOSURE') {
              if (!isset($this-&gt;item['enclosures'])) {
                  $this-&gt;item['enclosures'] = array();
              }
  
              $this-&gt;item['enclosures'][] = array_change_key_case($this-&gt;attribs, CASE_LOWER);
              $this-&gt;attribs = array();
          }
  
          $this-&gt;activeTag = '';
      }
  
      // }}}
      // {{{ cdataHandler()
  
      /**
       * Handler for character data
       *
       * @access private
       * @param  object XML parser object
       * @param  string CDATA
       * @return void
       */
      function cdataHandler($parser, $cdata)
      {
          if (in_array($this-&gt;insideTag, $this-&gt;parentTags)) {
              $tagName = strtolower($this-&gt;insideTag);
              $var = $this-&gt;{$tagName . 'Tags'};
  
              if (in_array($this-&gt;activeTag, $var) ||
                  in_array($this-&gt;activeTag, $this-&gt;moduleTags)) {
                  $this-&gt;_add($tagName, strtolower($this-&gt;activeTag),
                              $cdata);
              }
  
          }
      }
  
      // }}}
      // {{{ defaultHandler()
  
      /**
       * Default handler for XML parser
       *
       * @access private
       * @param  object XML parser object
       * @param  string CDATA
       * @return void
       */
      function defaultHandler($parser, $cdata)
      {
          return;
      }
  
      // }}}
      // {{{ _add()
  
      /**
       * Add element to internal result sets
       *
       * @access private
       * @param  string Name of the result set
       * @param  string Fieldname
       * @param  string Value
       * @return void
       * @see    cdataHandler
       */
      function _add($type, $field, $value)
      {
          if (empty($this-&gt;{$type}) || empty($this-&gt;{$type}[$field])) {
              $this-&gt;{$type}[$field] = $value;
          } else {
              $this-&gt;{$type}[$field] .= $value;
          }
  
          $this-&gt;last = $this-&gt;{$type};
      }
  
      // }}}
      // {{{ getStructure()
  
      /**
       * Get complete structure of RSS file
       *
       * @access public
       * @return array
       */
      function getStructure()
      {
          return (array)$this-&gt;struct;
      }
  
      // }}}
      // {{{ getchannelInfo()
  
      /**
       * Get general information about current channel
       *
       * This method returns an array containing the information
       * that has been extracted from the &lt;channel&gt;-tag while parsing
       * the RSS file.
       *
       * @access public
       * @return array
       */
      function getChannelInfo()
      {
          return (array)$this-&gt;channel;
      }
  
      // }}}
      // {{{ getItems()
  
      /**
       * Get items from RSS file
       *
       * This method returns an array containing the set of items
       * that are provided by the RSS file.
       *
       * @access public
       * @return array
       */
      function getItems()
      {
          return (array)$this-&gt;items;
      }
  
      // }}}
      // {{{ getImages()
  
      /**
       * Get images from RSS file
       *
       * This method returns an array containing the set of images
       * that are provided by the RSS file.
       *
       * @access public
       * @return array
       */
      function getImages()
      {
          return (array)$this-&gt;images;
      }
  
      // }}}
      // {{{ getTextinputs()
  
      /**
       * Get text input fields from RSS file
       *
       * @access public
       * @return array
       */
      function getTextinputs()
      {
          return (array)$this-&gt;textinputs;
      }
  
      // }}}
  
  }
  ?&gt;
  </code></pre>
  
  <p>However, this code doesn't work anymore or I am not testing it correctly...I am running it on xampp on mac.</p>
  
  <p>I wanted to make something like this:</p>
  
  <p>The user enters a term and I want to display the RSS feeds from Yahoo, Google or NYTimes.</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: I got two files RSS.php and Parser.php from a site last year and now it looks like the site is down. I am trying to see if anyone can offer another solution. Thanks!</p>