parsing rss file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lemonfreshmedia
Forum Commoner
Posts: 26
Joined: Fri Dec 02, 2005 7:14 pm

parsing rss file

Post by lemonfreshmedia »

I'm having trouble trimming the top article of an rss feed using the following code.
It trims the 'sponsored ad once every 25 or so refreshes.
It keeps forcing this ad into the top of my list of articles.

The feed always ads 'Save Up to 75% on Last-Minute Cruises - Sponsored Link'

here's my code. Wondering if i could position the table or cells using negative height (-42) for example to his ethe top article somehow.

The feed always contains this xml tag in the first item (AKA the Sponsored link)
<guid isPermaLink="false">ad20051209120000</guid>

Can anyone help trim this sponsored ad from the top of my parsed List?

Code: Select all

<?php

class RSSParser22 {

  /* The number of items to retrieve */
  var $maxitems = 10;
  
  var $insideitem = false;
  var $tag = "";
  var $title = "";
  var $description = "";
  var $link = "";
  var $blank = "_blank";
  var $none = "nolink";
  var $mycounter = "fakdjhfjkadhjklas";

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

function endElement($parser, $tagName) {
  if ($tagName == "ITEM") {
    printf("<tr><td height=\"42\" class=\"columns-front\"><a href='%s' target=&$blank&>%s</a>",
    trim($this->link),(trim($this->title)));
    printf("<br><b>%s<b></tr></td>",($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;
        $mycounter++;
        break;
      case "SOURCE":
        $this->description .= $data;
        break;
      case "LINK":
        $this->link .= $data;
        break;
    }
  }
}
}

$xml_parser = xml_parser_create();
$rss_parser = new RSSParser22();

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://p.moreover.com/page?o=rss002&c=Gaming%20news","r")
  or die("Error reading RSS data.");

/* Reads in all the data at once
   into a temporary variable */
while ($data = fread($fp, 4096)) {
  $tmp .= $data;
}

/* Splits up (tmp) into items */
$items = split('</item>', $tmp);

/* Cycles thru (items) with (maxitems) iterations */
for ($i = 0, $i[($this->title) != "Save Up to 75% on Last-Minute Cruises - Sponsored Link"], $i != 1; $i < $rss_parser->maxitems; $i++) {
  
  $xml .= $items[$i].'</item>';
}
$xml .= $items[sizeof($items)-1]; //<-- The remaining XML

xml_parse($xml_parser, $xml);

fclose($fp);
xml_parser_free($xml_parser);
$xml = null;
$data =null;
$items =null;
$tmp = null;
?>
Post Reply