PHP generates RSS file class instances

Source: Internet
Author: User
Tags generator

PHP RSS generated class instance code is as follows:

code is as follows: <?php


if (defined (' _class_rss_php ')) return;


define (' _class_rss_php tutorial ', 1);


/**


 


* Use instructions:


* $rss = new RSS (' Redfox ', ' http://jb51.net/', ' redfox ' blog ');


* $rss->additem (' RSS class ', ' http://www.jb51.net ', ' xxx ', date ());


* $rss->additem (...);


* $rss->savetofile (...);


 */


 


class RSS {


//public


$rss _ver = "2.0";


$channel _title = ';


$channel _link = ';


$channel _description = ';


$language = ' ZH_CN ';


$copyright = ';


$webmaster = ';


$pubdate = ';


$lastbuilddate = ';


$generator = ' redfox rss generator ';


 


$content = ';


$items = Array ();


 


function rss ($title, $link, $description) {


$this->channel_title = $title;


$this->channel_link = $link;


$this->channel_description = $description;


$this->pubdate = Date (' y-m-d h:i:s ', Time ());


$this->lastbuilddate = Date (' y-m-d h:i:s ', Time ());


   }


 


function additem ($title, $link, $description, $pubdate) {


$this->items[] = Array (' Titile ' => $title,


' link ' => $link,


' description ' => $description,


' pubdate ' => $pubdate);


   }


 


function Buildrss () {


$s = "<!--l version=" 1.0 "encoding=" gb2312 "-->";


Start Channel


$s. = "";


$s. = ""


$s. = "<link/>{$this->channel_link}";


$s. = "{$this->channel_description}";


$s. = "{$this->language}";


if (!emptyempty ($this->copyright)) {


$s. = "{$this->copyright}";


       }


if (!emptyempty ($this->webmaster)) {


$s. = "{$this->webmaster}";


       }


if (!emptyempty ($this->pubdate)) {


$s. = "{$this->pubdate}";


       }


 


if (!emptyempty ($this->lastbuilddate)) {


$s. = "{$this->lastbuilddate}";


       }


 


if (!emptyempty ($this->generator)) {


$s. = "{$this->generator}";


       }


      


//Start Items


for ($i =0 $iitems), $i + +) {


$s. = "";


$s. = "";


$s. = "<link/>{$this->items[$i [' Link ']}";


$s. = "<!--data[{$thi-->items[$i] [' description ']}]]> '];


$s. = "{$this->items[$i] [' pubdate ']}";


$s. = "";


       }


     


//Close channel


$s. = "";


$this->content = $s;


   }


 


function Show () {


if (Emptyempty ($this->content)) $this->buildrss ();


header (' Content-type:text/xml ');


Echo ($this->content);


   }


 


function SaveToFile ($fname) {


if (Emptyempty ($this->content)) $this->buildrss ();


$handle = fopen ($fname, ' WB ');


if ($handle = = false) return false;


fwrite ($handle, $this->content);


Fclose ($handle);


   }


}


?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.