Jump to content

Recommended Posts

Hi everyone. I'm not too up on XML (shame on me!)

 

I've written the following class, but it keeps getting an encoding error... I know the other elements of the procedure (the other scripts) are right... or at least I think they are.

 

I've narrowed the issue down to somewhere in this script (probably the first few lines)

 

Can anyone help? I'm lost!

 

Thanks,

Neil

<?php
class RSSFeed {
// VARIABLES
    // channel vars
    var $channel_url;
    var $channel_title;
    var $channel_description;
    var $channel_lang;
    var $channel_copyright;
    var $channel_date;
    var $channel_creator;
    var $channel_subject;   
    // image
    var $image_url;
    // items
    var $items = array();
    var $nritems;
    
// FUNCTIONS
    // constructor
    function RSSFeed() {
            $this->nritems=0;
        $this->channel_url='';
        $this->channel_title='';
        $this->channel_description='';
        $this->channel_lang='';
        $this->channel_copyright='';
        $this->channel_date='';
        $this->channel_creator='';
        $this->channel_subject='';
        $this->image_url='';
    }   
    // set channel vars
    function SetChannel($url, $title, $description, $lang, $copyright, $creator, $subject) {
        $this->channel_url=$url;
        $this->channel_title=$title;
        $this->channel_description=$description;
        $this->channel_lang=$lang;
        $this->channel_copyright=$copyright;
        $this->channel_date=date("Y-m-d").'T'.date("H:i:s").'+01:00';
        $this->channel_creator=$creator;
        $this->channel_subject=$subject;
    }
    // set image
    function SetImage($url) {
        $this->image_url=$url;  
    }
    // set item
    function SetItem($url, $title, $description) {
        $this->items[$this->nritems]['url']=$url;
        $this->items[$this->nritems]['title']=$title;
        $this->items[$this->nritems]['description']=$description;
        $this->nritems++;   
    }
    // output feed
    function Output() {
        $output .= '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
		$output .='<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">'."\n";
        $output .= '<channel>'."\n"; # rdf:about="'.$this->channel_url.'">'."\n";
        $output .= '<title>'.$this->channel_title.'</title>'."\n";
        $output .= '<atom:link href="http://www.tingifts.co.uk/blog/" rel="self" type="application/rss+xml"/>'."\n";
		$output .= '<link>'.$this->channel_url.'</link>'."\n";
        $output .= '<description>'.$this->channel_description.'</description>'."\n";
        $output .= '<lastBuildDate>'.$this->channel_date.'</lastBuildDate>'."\n";
        $output .= '<language>'.$this->channel_lang.'</language>'."\n";
        $output .= '<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>'."\n";
		$output .= '<generator>http://www.tingifts.co.uk</generator>'."\n";
		$output .= '<item>'."\n";
        for($k=0; $k<$this->nritems; $k++) {
            
            $output .= '<title>'.$this->items[$k]['title'].'</title>'."\n";
            $output .= '<link>'.$this->items[$k]['url'].'</link>'."\n";
			$output .= '<image>'."\n";
			$output .= '   <url>'.$this->image_url.'</url>'."\n";
			$output .= '   <title>'.$this->items[$k]['title'].'</title>'."\n";
    		$output .= '   <link>'.$this->items[$k]['url'].'</link>'."\n";
			$output .= '</image>';
            $output .= '<description>'.$this->items[$k]['description'].'</description>'."\n";
        };
		$output .= '</item>'."\n";
		$output .= '</channel>'."\n";
		$output .= '</rss>'."\n";

        return $output;
    }
};
?>

Not too up on PHP it seems either. That's 12+ years old code (look Mom, a dinosaur!). var is now public but this violates the encapsulation and should really be private. The old style constructor function RSSFeed() which was popular in PHP 4.0 but is now replaced by __construct in PHP5 (released in 2003).

 

And we are going to need the exact error as the code itself runs fine.

 

PS No offense intended, but that code is really old!

Edited by ignace

No offence taken... It's not my script. I just changed it. Was RSS around 12+ years ago?

 

The error is found with the output: error on line 42 at column 8: Encoding error

 
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.