php - getting RSS feeds on website -


i had code wrote last year , returns rss feeds term enter:

<html> <body>  <form name="form" action="search.php" method="get">   <input type="text" name="q" />   <input type="submit" name="submit" value="search" /> </form>  <?php   require_once "rss.php";   // want parse $row[1] variable out words, make new string + instead of spaces   $college = "college";  $collegelen= strlen($college);  for($i = 0; $i < $collegelen; $i++){ if ($college{$i} == " ") {$spaced = $spaced . "+";} else {$spaced = $spaced . $college{$i};} }  echo("yahoo! news rss");  $rss_yahoo =& new xml_rss("http://news.search.yahoo.com/news/rss?p=" . $spaced . "&ei=utf-8&fl=0&x=wrt"); $rss_yahoo->parse();  foreach ($rss_yahoo->getitems() $item) {   echo "<li><a href=\"" . $item['link'] . "\">" . $item['title'] . "</a></li><br>"; //echo $item['pubdate'] ."<br>";   echo $item['description'] . "<br><br>\n"; }  //echo("google rss");  //$rss_google =& new xml_rss("http://news.google.com/news?hl=en&ned=us&q=" . $spaced . "&ie=utf-8&nolr=1&output=rss"); //$rss_google->parse();  //foreach ($rss_google->getitems() $item) { //  echo "<li><a href=\"" . $item['link'] . "\">" . $item['title'] . "</a></li><br>"; //  echo $item['description'] . "<br><br>\n"; }  echo("google rss");  $rss_google =& new xml_rss("http://news.google.com/news?hl=en&ned=us&q=" . $spaced . "&ie=utf-8&nolr=1&output=rss"); $rss_google->parse();  foreach ($rss_google->getitems() $item) {   echo "<li><a href=\"" . $item['link'] . "\">" . $item['title'] . "</a></li><br>"; - hide quoted text -  "<br><br>\n"; }  ?>  </body> </html> 

rss.php

<?php // vim: set expandtab tabstop=4 shiftwidth=4 fdm=marker: // +----------------------------------------------------------------------+ // | php version 4                                                        | // +----------------------------------------------------------------------+ // | copyright (c) 1997-2003 php group                                | // +----------------------------------------------------------------------+ // | source file subject version 2.02 of php license,      | // | bundled package in file license, ,        | // | available @ through world-wide-web @                           | // | http://www.php.net/license/2_02.txt.                                 | // | if did not receive copy of php license , unable   | // | obtain through world-wide-web, please send note          | // | license@php.net can mail copy immediately.               | // +----------------------------------------------------------------------+ // | authors: martin jansen <mj@php.net>                                  | // |                                                                      | // +----------------------------------------------------------------------+ // // $id: rss.php,v 1.28 2006/09/14 08:40:05 clay exp $ //  require_once 'parser.php';  /** * rss parser class. * * class parser resource description framework (rdf) site * summary (rss) documents. more information on rss see * website of rss working group (http://www.purl.org/rss/). * * @author martin jansen <mj@php.net> * @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      *      * 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 rss file, or rss string.      * @param string  source charset encoding, use null (default) use      *                default encoding (iso-8859-1)      * @param string  target charset encoding, use null (default) use      *                default encoding (iso-8859-1)      * @return void      */     function xml_rss($handle = '', $srcenc = null, $tgtenc = null)     {         if ($srcenc === null && $tgtenc === null) {             $this->xml_parser();         } else {             $this->xml_parser($srcenc, 'event', $tgtenc);         }          $this->setinput($handle);          if ($handle == '') {             $this->raiseerror('no input passed.');         }     }      // }}}     // {{{ starthandler()      /**      * start element handler 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->insidetag = $element;                 array_push($this->insidetagstack, $element);                 break;              case 'enclosure' :                 $this->attribs = $attribs;                 break;              default:                 $this->activetag = $element;         }     }      // }}}     // {{{ endhandler()      /**      * end element handler xml parser      *      * if end of <item>, <channel>, <image> or <textinput>      * reached, method updates structure array      * $this->struct[] , adds field "type" array,      * defines type of 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->insidetag) {             array_pop($this->insidetagstack);             $this->insidetag = end($this->insidetagstack);              $this->struct[] = array_merge(array('type' => strtolower($element)),                                           $this->last);         }          if ($element == 'item') {             $this->items[] = $this->item;             $this->item = '';         }          if ($element == 'image') {             $this->images[] = $this->image;             $this->image = '';         }          if ($element == 'textinput') {             $this->textinputs = $this->textinput;             $this->textinput = '';         }          if ($element == 'enclosure') {             if (!isset($this->item['enclosures'])) {                 $this->item['enclosures'] = array();             }              $this->item['enclosures'][] = array_change_key_case($this->attribs, case_lower);             $this->attribs = array();         }          $this->activetag = '';     }      // }}}     // {{{ cdatahandler()      /**      * handler character data      *      * @access private      * @param  object xml parser object      * @param  string cdata      * @return void      */     function cdatahandler($parser, $cdata)     {         if (in_array($this->insidetag, $this->parenttags)) {             $tagname = strtolower($this->insidetag);             $var = $this->{$tagname . 'tags'};              if (in_array($this->activetag, $var) ||                 in_array($this->activetag, $this->moduletags)) {                 $this->_add($tagname, strtolower($this->activetag),                             $cdata);             }          }     }      // }}}     // {{{ defaulthandler()      /**      * default handler xml parser      *      * @access private      * @param  object xml parser object      * @param  string cdata      * @return void      */     function defaulthandler($parser, $cdata)     {         return;     }      // }}}     // {{{ _add()      /**      * add element internal result sets      *      * @access private      * @param  string name of result set      * @param  string fieldname      * @param  string value      * @return void      * @see    cdatahandler      */     function _add($type, $field, $value)     {         if (empty($this->{$type}) || empty($this->{$type}[$field])) {             $this->{$type}[$field] = $value;         } else {             $this->{$type}[$field] .= $value;         }          $this->last = $this->{$type};     }      // }}}     // {{{ getstructure()      /**      * complete structure of rss file      *      * @access public      * @return array      */     function getstructure()     {         return (array)$this->struct;     }      // }}}     // {{{ getchannelinfo()      /**      * general information current channel      *      * method returns array containing information      * has been extracted <channel>-tag while parsing      * rss file.      *      * @access public      * @return array      */     function getchannelinfo()     {         return (array)$this->channel;     }      // }}}     // {{{ getitems()      /**      * items rss file      *      * method returns array containing set of items      * provided rss file.      *      * @access public      * @return array      */     function getitems()     {         return (array)$this->items;     }      // }}}     // {{{ getimages()      /**      * images rss file      *      * method returns array containing set of images      * provided rss file.      *      * @access public      * @return array      */     function getimages()     {         return (array)$this->images;     }      // }}}     // {{{ gettextinputs()      /**      * text input fields rss file      *      * @access public      * @return array      */     function gettextinputs()     {         return (array)$this->textinputs;     }      // }}}  } ?> 

however, code doesn't work anymore or not testing correctly...i running on xampp on mac.

i wanted make this:

the user enters term , want display rss feeds yahoo, google or nytimes.

thanks!

edit: got 2 files rss.php , parser.php site last year , looks site down. trying see if can offer solution. thanks!

maybe try simplepie. it's easy use , have active development. can start using right away, or reading documentation more advance usage.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -