[GLLUG] PHP Help

Thomas Alan Hearn hearntho at msu.edu
Tue Jul 12 19:22:07 EDT 2005


Nick,
  Here is a script that I had written in the past for my own website, feel 
free to use as necessary: 

<?
class RSSParser { 

  var $insideitem = false;
  var $tag = "";
  var $title = "";
  var $description = "";
  var $link = ""; 

  function startElement($parser, $tagName, $attrs) {
      if ($this->insideitem) {
          $this->tag = $tagName;
      } elseif ($tagName == "ITEM") {
          $this->insideitem = true;
      }
  } 

  function endElement($parser, $tagName) {
      if ($tagName == "ITEM") {
          printf("<p><b><a href='%s'>%s</a></b></p>",
            trim($this->link),htmlspecialchars(trim($this->title)));
          printf("<p>%s</p>",
            htmlspecialchars(trim($this->description)));
          $this->title = "";
          $this->description = "";
          $this->link = "";
          $this->insideitem = false;
      }
  } 

  function characterData($parser, $data) {
      if ($this->insideitem) {
          switch ($this->tag) {
              case "TITLE":
              $this->title .= $data;
              break;
              case "DESCRIPTION":
              $this->description .= $data;
              break;
              case "LINK":
              $this->link .= $data;
              break;
          }
      }
  }
} 

$xml_parser = xml_parser_create();
$rss_parser = new RSSParser();
xml_set_object($xml_parser,$rss_parser);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://www.tomhearn.com/feed.xml/blog","r")
  or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
  xml_parse($xml_parser, $data, feof($fp))
      or die(sprintf("XML error: %s at line %d",
          xml_error_string(xml_get_error_code($xml_parser)),
          xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);
?> 

Feel free to shoot questions to me if you need help in explaining what is 
going on. 

Cheers,
Tom 

Nick Kwiatkowski writes: 

> Hey Everybody! 
> 
>   
> 
>   I've involved myself with a company that needs some documentation written
> for a product they are producing.  They are going to be publishing RSS feeds
> with certain data, and they would like examples in all the major web-based
> languages to be included in their documentation.  Currently, they have docs
> written for ASP.NET, ASP Classic, MM/BD Coldfusion.  We were looking for
> somebody to help us write some documentation on implementing the RSS feeds
> in PHP.  If you are interested, please email me back at kwiatk27 at msu.edu.
> We do have a budget for this project, and are willing to pay per-hour for
> the work completed. 
> 
>   
> 
> Thanks! 
> 
>   
> 
> -Nick Kwiatkowski 
> 
>   
> 
 




More information about the linux-user mailing list