PHP generated RSS File class instance
The PHP RSS Generation class instance code is as follows:
The code is as follows:
if (defined (' _class_rss_php ')) return;
Define (' _class_rss_php tutorial ', 1);
/**
* Instructions for use:
* $rss = new RSS (' Redfox ', ' http://jb51.net/', "Redfox ' s 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 ' and $link,
' Description ' = $description,
' pubdate ' = $pubdate);
}
function Buildrss () {
$s = " ";
Start Channel
$s. = "";
$s. = ""
$s. = " {$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. = " {$this->items[$i] [' Link ']} ";
$s. = " 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);
}
}
?>
http://www.bkjia.com/PHPjc/922888.html www.bkjia.com true http://www.bkjia.com/PHPjc/922888.html techarticle PHP generated RSS file class instance PHP RSS generated class instance code as follows: The code is as follows: PHP if (defined (' _class_rss_php ')) return; define (' _class_rss_php tutorial ', 1);/** * Instructions for use: * ...