Jump to content

RSS Parser stops working...


ndisdabest

Recommended Posts

Hi All --

 

So I've had this code in a page of mine for quite some time, and it just suddenly stopped working without any major changes being made to the code.  There is another person working on this site with me, but she swears she didn't make any changes, and after reviewing the code, it doesn't look like she did.  And actually, I'm using this same exact code on another site, and it's working perfectly fine.

 

It's an RSS Parser...  here's my code at the top of the page.  It's displaying the "XML Error" message that occurs because the WHILE loop at the top is hitting the "DIE" portion.  Nothing else shows up.

 

<?php
$itemNum=0;
class RSSParser	{
var $channel_title="";
var $channel_website="";
var $channel_description="";
var $channel_pubDate="";
var $channel_lastUpdated="";
var $channel_copyright="";
var $title="";
var $link="";
var $description="";
var $pubDate="";
var $author="";
var $url="";
var $width="";
var $height="";
var $inside_tag=false;	
function RSSParser($file)	{
		$this->xml_parser = xml_parser_create();
		xml_set_object( $this->xml_parser, &$this );
		xml_set_element_handler( $this->xml_parser, "startElement", "endElement" );
		xml_set_character_data_handler( $this->xml_parser, "characterData" );
		$fp = @fopen("$file","r") or die( "$file could not be opened" );
		while ($data = fread($fp, 4096)){xml_parse( $this->xml_parser, $data, feof($fp)) or die( "XML error");}
		fclose($fp);
		xml_parser_free( $this->xml_parser );
	}

function startElement($parser,$tag,$attributes=''){
	$this->current_tag=$tag;
	if($this->current_tag=="ITEM" || $this->current_tag=="IMAGE"){
		$this->inside_tag=true;
		$this->description="";
		$this->link="";
		$this->title="";
		$this->pubDate="";
	}
}

function endElement($parser, $tag){
	switch($tag){
		case "ITEM":
			$this->titles[]=trim($this->title);
			$this->links[]=trim($this->link);
			$this->descriptions[]=trim($this->description);
			$this->pubDates[]=trim($this->pubDate);
			$this->authors[]=trim($this->author);
			$this->author=""; $this->inside_tag=false;
			break;
		case "IMAGE":
			$this->channel_image="<img src=\"".trim($this->url)."\" width=\"".trim($this->width)."\" height=\"".trim($this->height)."\" alt=\"".trim($this->title)."\" border=\"0\" title=\"".trim($this->title)."\" />";
			$this->title=""; $this->inside_tag=false;
		default:
			break;
	}
}

function characterData($parser,$data){
	if($this->inside_tag){
		switch($this->current_tag){
			case "TITLE":
				$this->title.=$data; break;
			case "DESCRIPTION":
				$this->description.=$data; break;
			case "LINK":
				$this->link.=$data; break;
			case "URL":
				$this->url.=$data; break;					
			case "WIDTH":
				$this->width.=$data; break;
			case "HEIGHT":
				$this->height.=$data; break;
			case "PUBDATE":
				$this->pubDate.=$data; break;
			case "AUTHOR":
				$this->author.=$data;	break;
			default: break;									
		}//end switch
	}else{
		switch($this->current_tag){
			case "DESCRIPTION":
				$this->channel_description.=$data; break;
			case "TITLE":
				$this->channel_title.=$data; break;
			case "LINK":
				$this->channel_website.=$data; break;
			case "COPYRIGHT":
				$this->channel_copyright.=$data; break;
			case "PUBDATE":
				$this->channel_pubDate.=$data; break;					
			case "LASTBUILDDATE":
				$this->channel_lastUpdated.=$data; break;				
			default:
				break;
		}
	}
}
}
$mike= new RSSParser("http://feeds.feedburner.com/sommerfrieze");
?>

 

And here is how I call it:

 

<?php
			  
				$mike_RSSmax=4;
				if($mike_RSSmax==0 || $mike_RSSmax>count($mike->titles))$mike_RSSmax=count($mike->titles);
					for($itemNum=0;$itemNum<$mike_RSSmax;$itemNum++){?>
					<tr>
						<td width="10" valign="top"><span class="rightItem">> </span></td>
						<td width="145" valign="top"><a class="rightItem" href="<?php echo $mike->links[$itemNum]; ?>"><?php echo $mike->titles[$itemNum]; ?></a></td>
					</tr>
			<?php } ?>

 

Any ideas?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.