PHP generates RSS file class instance _php tips

Source: Internet
Author: User
Tags generator

This example describes the PHP generated RSS file class files. Share to everyone for your reference. Specifically as follows:

PHP RSS generated class instance code is as follows:

Copy Code code as follows:
<?php
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 ' => $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);
}
}
?>

I hope this article will help you with your PHP program design.

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.