Jump to content

PHP Class (to make XML) getting encoding error


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!




class RSSFeed {
    // 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;
    // constructor
    function RSSFeed() {
    // set channel vars
    function SetChannel($url, $title, $description, $lang, $copyright, $creator, $subject) {
    // set image
    function SetImage($url) {
    // set item
    function SetItem($url, $title, $description) {
    // 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>
		$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;
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

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

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.