A PHP class that generates RSS2.0

Source: Internet
Author: User
Tags date format array comments final generator php class rfc822
Rss

<?php
/*****************************************
* RSS2.0 Generator
* Create by Magicboy (darasion)
* Copyright? Magic Boy
******************************************/

/*————————————————

How to use:
Bring the following array into the corresponding function.

1. Channel Main body
$channel = Array (
Title => ' Channel name (required) ',
Link => ' channel URL (required) ',
Description of the Description => ' channel (required) ',
Language => ' The language of the Channel article (optional) ',
Webmaster => ' email to webmaster (optional) for channel technical affairs
Managingeditor => ' Editor's email (optional) ',
pubdate => ' channel content release date, format follows RFC822 format (year can be 2-bit or 4-bit) (optional) ',
Lastbuilddate => ' channel content final modification date (Sat, SEP 2002 09:42:31 GMT) (optional) ',
Skipdays => ' Hint news aggregator, those days it can skip. (optional) ',
Copyright => ' channel content (optional) ',
TTL => ' validity period to indicate the maximum time (optional) that the channel can be cached.
);

2, channel picture
$image = Array (
URL => ' picture link (required) ',
Title => ' picture caption, for HTTP ALT attribute (required) ',
The URL of the link => ' site (often replaced by the URL of the channel) (required) ',
Width => ' picture (pixels) Max 144, default 88 (optional) ',
Height => ' picture (pixel) Max 400, default 31 (optional) ',
Description => ' title attribute for link (optional) '
);

3, channel item
$item = Array (
 title => ' Item) title (required) ',
 description => ' Outline of item (required) ', URL of
 link => ' item (required) ',
 comments => ' The URL of the comment (comments) page for the item (optional) ',
 guid => ' 1 unique identifier string (optional) ',
 author => ' email (optional) for the author,
 enclosure => ' describes the accompanying media object (optional) ',
  Category => ' contains one or more categories (catogory) (optional) of the item (optional) ',
 pubdate => ' The publication time of the item (optionally) ',
 source_url => ' This entry is from the RSS feed (optional) ',
 source_name => ' The RSS feed (optional) from
);
———————————————— */

Class Rss2
{
var $channel _pre= "";
var $str _image= "";
var $str _item= "";
var $channel _end= "";
/* Constructor/*
function Rss2 ($channel, $encoding = "GB2312")
{
$this->channel ($channel, $encoding);
}
/* Generate Channel main body * *
function channel ($channel, $encoding = "GB2312")
{
$this->channel_pre.= "<?xml version=\" 1.0\ "encoding=\" $encoding \ ">\n";
$this->channel_pre.= "<rss version=\" 2.0\ ">\n";

$this->channel_pre.= "<channel>\n";

$this->channel_pre.= "<title>". $channel [' title ']. " </title>\n ";//Channel name (required)
$this->channel_pre.= "<link>". $channel [' link ']. " </link>\n ";//channel URL (required)
$this->channel_pre.= "<description>". $channel [' description ']. " </description>\n ";/the description of the channel (required)
$this->channel_pre.= "<generator>magicboy RSS generator v1.0</generator>\n";/The program that created this document (optional)

if (Isset ($channel [' language ']) $this->channel_pre.= "<language>". $channel [' language ']. " </language>\n "//Channel article language (optional)
if (Isset ($channel [' webmaster ']) $this->channel_pre.= "<webMaster>". $channel [' webmaster ']. " </webmaster>\n "//the webmaster for the channel Technical Affairs email (optional)
if (Isset ($channel [' Managingeditor ']) $this->channel_pre.= "<managingEditor>". $channel [' Managingeditor ' ]." </managingeditor>\n ";//Editor's email (optional)
if (Isset ($channel [' pubdate ']) $this->channel_pre.= "<pubDate>". $channel [' pubdate ']. " </pubdate>\n ";//channel content release date, format follows RFC822 format (year can be 2-bit or 4-bit) (optional)
if (Isset ($channel [' lastbuilddate ']) $this->channel_pre.= "<lastBuildDate>". $channel [' lastbuilddate ']. " </lastbuilddate>\n "//channel Content final modification date (Sat, SEP 2002 09:42:31 GMT) (optional)
if (Isset ($channel [' skipdays ']) $this->channel_pre.= "<skipDays>". $channel [' skipdays ']. " </skipdays>\n "//Hint news aggregator, those days it can skip. (optional)
if ($channel [' copyright ']) $this->channel_pre.= "<copyright>" $channel [' copyright ']. "Isset </copyright>\n "//Copyright description of the content of the channel (optional)
if (Isset ($channel [' TTL ']) $this->channel_pre.= "<ttl>" $channel [' TTL ']. " </ttl>\n "//validity period to indicate the maximum time that the channel can be cached (optional)

$this->channel_end.= "</channel>\n";
$this->channel_end.= "</rss>\n";
}
/* Generate Channel Picture * *
function Image ($image)
{
if (Isset ($this->str_image)) unset ($this->str_image);
$this->str_image.= "<image>\n";
if (Isset ($image [' url '])) $this->str_image.= "<url>" $image [' url ']. " </url>\n ";//the URL of the picture (required)
if ($image [' title ']) $this->str_image.= "<title>" $image [' title ']. "Isset </title>\n ";//caption of the picture, alt attribute for HTTP (required)
if (Isset ($image [' link ']) $this->str_image.= "<link>" $image [' link ']. " </link>\n the URL of the Web site (often replaced by a channel URL) (required)
if (Isset ($image [' width ']) $this->str_image.= "<width>". $image [' width ']. " </width>\n ";//Picture width (pixel) Max 144, default 88 (optional)
if (Isset ($image [' height ']) $this->str_image.= "if (Isset ($image [' description ']) $this->str_image.= "<description>". $image [' description ']. " </description>\n ";//For Link's Title property (optional)
$this->str_image.= "</image>\n";
}
/* Channel Item * *
function Item ($ITEM)
{
$this->str_item.= "<item>\n";
$this->str_item.= "<title>". $item [' title ']. " Title of </title>\n ";/item" (required)
$this->str_item.= "<description>". $item [' description ']. " </description>\n ";//Outline of item (required)
$this->str_item.= "<link>". $item [' link ']. " </link>\n ";//URL of item (required)

if (Isset ($item [' comments ']) $this->str_item.= "<comments>". $item [' comments ']. " </comments>\n The URL of the comment (comments) page for the item (optional)
if (Isset ($item [' GUID ']) $this->str_item.= "<guid>" $item [' GUID ']. " </guid>\n ";//1 unique marker string (optional)
if (Isset ($item [' author ']) $this->str_item.= "<author>". $item [' author ']. " </author>\n "//The author's email (optional)
if (Isset ($item [' Enclosure ']) $this->str_item.= "<enclosure>". $item [' Enclosure ']. " </enclosure>\n ";//describe the accompanying media object (optional)
if (Isset ($item [' Category ']) $this->str_item.= "<category>". $item [' category ']. " </category>\n ";//(optional) One or more categories (catogory) containing the item
if (Isset ($item [' pubdate ']) $this->str_item.= "<pubDate>". $item [' pubdate ']. " </pubdate>\n (optional) When the item is published
if (Isset ($item [' Source_url ']) $this->str_item.= "<source url=\" ". $item [' Source_url ']." \ > $item [' source_name ']. " </source>\n ";/the RSS feed from the item (optional)
$this->str_item.= "</item>\n";
}
/* Output xml*/
function Generate ()
{
if (Isset ($this->channel_pre) &&isset ($this->channel_end) &&isset ($this->str_item))
{
Header ("Content-type:text/xml");
Echo $this->channel_pre;
Echo $this->str_image;
Echo $this->str_item;
Echo $this->channel_end;
}
}
* Erase Channel/*
function Erase_channel ()
{
unset ($this->channel_pre);
unset ($this->channel_end);
}
/* Erase Channel Picture * *
function Erase_image ()
{
unset ($this->str_image);
}
/* Erase Items * *
function Erase_item ()
{
unset ($this->str_item);
}
/* Erase all */
function Erase ()
{
$this->erase_channel ();
$this->erase_image ();
$this->erase_item ();
}
}
?>



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.