PHP generates an RSS file instance. PHP generates an RSS file instance. the code of the PHPRSS generation class instance is as follows :? Phpif (defined (_ class_rss_php) return; define (_ class_rss_php tutorial, 1); *** instructions for use: * PHP generates an RSS File Class instance
The code of the php rss generation class instance is as follows:
The code is as follows:
If (defined ('_ class_rss_php') return;
Define ('_ class_rss_php tutorial', 1 );
/**
* Instructions:
* $ 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 ('tile' => $ title,
'Link' => $ 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 the 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 );
}
}
?>
The following code generates an example of the php rss generation class :? Php if (defined ('_ class_rss_php') return; define ('_ class_rss_php tutorial', 1);/*** instructions for use :*...