Php of a generation of RSS2.0
The want to write a blog in the past, but due to lack of time, some of its own code is not feeling well, so a drop Later that csdn out blog, huh. Under this good, do not have their own work to. .
Now given a written can also think of the php code, the code reference bamboo shoots Chaorou the RSS 2.0 specification this article.
Due to its limited level of xml was not very understanding, we hope that the masses enthusiastically criticism corrected, thank you.
<? Php
/*****************************************
* RSS2.0 Generator
* Create by MagicBoy (darasion)
* Copyright? Magical boys
******************************************/
/*—————-
Method of Use:
Below will be an array, into the corresponding function.
1, the main channel
$ Channel = array (
Title => 'channel name (required)',
Link => 'channel URL (required)',
Description => 'description of the channel (required)',
Language => 'language channel article (optional)',
Webmaster => 'channel Technology Services is responsible for the webmaster email (optional)',
ManagingEditor => 'responsibility to edit the email (optional)',
PubDate => 'channel content distribution date format followed RFC822 format (for two years or 4) (optional)',
LastBuildDate => 'channel content of the revised final date (Sat, 07 Sep 2002 09:42:31 GMT) (optional)',
SkipDays => 'Reminder news aggregator, it can skip those days. (Optional) ',
Copyright => 'copyright content channel (optional)',
Ttl => 'period to be specified in the channel, the longest period of cache (optional)',
);
2, channel picture
$ Image = array (
Url => 'picture links (required)',
Title => 'picture heading for the http alt attributes (required)',
Link => 'website url (actual often to replace the channel url) (required)',
Width => 'picture width (pixels) for the largest 144, the default 88 (optional)',
Height => 'picture height (pixels) for the largest 400, the default 31 (optional)',
Description => 'is used to link the title attribute (optional)'
);
3, the channel
$ Item = array (
Title => 'item (item) title (required)',
Description => 'outline of the (necessary)',
Link => 'of the URL (required)',
Comments => 'of the comments (comments) page URL (optional)',
Guid =>'1 the only item identifier string (optional) ',
Author => 'The author's email (optional)',
Enclosure => 'description of the fringe media targets (optional)',
Category => 'contains one or several of the Classification (catogory) (optional)',
Pubdate => 'time of the release (optional)',
Source_url => 'The Road from the RSS (optional)',
Source_name => 'The Road from the RSS (optional)'
);
—————-*/
Class rss2
(
Var $ channel_pre = "";
Var $ str_image = "";
Var $ str_item = "";
Var $ channel_end = "";
/ * Constructor function * /
Function rss2 ($ channel, $ encoding = "GB2312")
(
$ This-> channel ($ channel, $ encoding);
)
/ * Main channel formation * /
Function channel ($ channel, $ encoding = "GB2312")
(
$ This-> channel_pre .="<? xml version = \ "1 \" 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 "/ / channel description (required)
$ This-> channel_pre .= "<generator> MagicBoy RSS Generator v1.0 </ generator> \ n" / / create this document procedures (optional)
If (isset ($ channel [ 'language']))$ this-> channel_pre .= "<language>." $ Channel [' language']."</ language> \ n "/ / channel used by the language article ( optional)
If (isset ($ channel [ 'webmaster']))$ this-> channel_pre .= "<webMaster>." $ Channel [' webmaster']."</ webMaster> \ n "/ / channel responsible for the Technical Services webmaster email (optional)
If (isset ($ channel [ 'managingeditor']))$ this-> channel_pre .= "<managingEditor>." $ Channel [' managingeditor']."</ managingEditor> \ n "/ / Editor of the email ( optional)
If (isset ($ channel [ 'pubdate']))$ this-> channel_pre .= "<pubDate>." $ Channel [' pubdate']."</ pubDate> \ n "/ / channel content distribution date, format followed RFC822 format (for two years or 4) (optional)
If (isset ($ channel [ 'lastbuilddate']))$ this-> channel_pre .= "<lastBuildDate>." $ Channel [' lastbuilddate']."</ lastBuildDate> \ n "/ / channel content of the final changes Date (Sat, 07 Sep 2002 09:42:31 GMT) (optional)
If (isset ($ channel [ 'skipdays']))$ this-> channel_pre .= "<skipDays>." $ Channel [' skipdays']."</ skipDays> \ n "/ / Tips news aggregator, It can skip those days. (Optional)
If (isset ($ channel [ 'copyright']))$ this-> channel_pre .= "<copyright>." $ Channel [' copyright']."</ copyright> \ n "/ / channel content Copyright (optional)
If (isset ($ channel [ 'ttl']))$ this-> channel_pre .= "<ttl>." $ Channel [' ttl']."</ ttl> \ n "/ / valid for the specified The channel may be the most prolonged cache (optional)
$ This-> channel_end .= "</ channel> \ n";
$ This-> channel_end .= "</ rss> \ n";
)
/ * Generation Rate picture * /
Function image ($ image)
(
If (isset ($ this-> str_image)) unset ($ this-> str_image);
$ This-> str_image .= "<image> \ n";
If (isset ($ image [ '']))$ this url-> str_image .= "<url>." $ Image [' url']."</ url> \ n "/ / url picture of the (Bi Preparation)
If (isset ($ image [ 'title']))$ this-> str_image .= "<title>." $ Image [' title']."</ title> \ n "/ / the title picture with http in the alt attributes (required)
If (isset ($ image [ '']))$ this link-> str_image .= "<link>." $ Image [' link']."</ link> \ n "/ / Web site url (actual url to the channel often substitute) (required)
If (isset ($ image [ 'width']))$ this-> str_image .= "<width>." $ Image [' width']."</ width> \ n "/ / picture width (like -) for the largest 144, the default 88 (optional)
If (isset ($ image [ 'height']))$ this-> str_image .= "<height>." $ Image [' height']."</ height> \ n "/ / picture height (like -) for the largest 400, the default 31 (optional)
If (isset ($ image [ 'description']))$ this-> str_image .= "<description>." $ Image [' description']."</ description> \ n "/ / link to the title Attribute (optional)
$ This-> str_image .= "</ image> \ n";
)
/ * * The channel /
Function item ($ item)
(
$ This-> str_item .= "<item> \ n";
$ This-> str_item .= "<title>." $ Item [ 'title']."</ title> \ n "/ / item (item) title (required)
$ This-> str_item .= "<description>." $ Item [ 'description']."</ description> \ n "/ / outline of the (necessary)
$ This-> str_item .= "<link>." $ Item [ 'link']."</ link> \ n "/ / URL of the (necessary)
If (isset ($ item [ 'comments']))$ this-> str_item .= "<comments>." $ Item [' comments']."</ comments> \ n "/ / The comments ( comments) page URL (optional)
If (isset ($ item [ 'guid']))$ this-> str_item .= "<guid>." $ Item [' guid']."</ guid> \ n "/ / the only one identifier 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 "/ / description of the fringe media Object (optional)
If (isset ($ item [ 'category']))$ this-> str_item .= "<category>." $ Item [' category']."</ category> \ n "/ / contain the one or several Classification (catogory) (optional)
If (isset ($ item [ 'pubdate']))$ this-> str_item .= "<pubDate>." $ Item [' pubdate']."</ pubDate> \ n "/ / time of the release ( optional)
If (isset ($ item [ 'source_url']))$ this-> str_item .= "<source url=\"".$item['source_url']."\">." $ Item [' source_name '] . "</ source> \ n" / / The Road from the RSS (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 channels * /
Function erase_channel ()
(
Unset ($ this-> channel_pre);
Unset ($ this-> channel_end);
)
/ * Erase channel picture * /
Function erase_image ()
(
Unset ($ this-> str_image);
)
/ * * Erase /
Function erase_item ()
(
Unset ($ this-> str_item);
)
/ * Erase all * /
Function erase ()
(
$ This-> erase_channel ();
$ This-> erase_image ();
$ This-> erase_item ();
)
)
–>
Tags: PHP








0 Comments to “Php of a generation of RSS2.0”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.