|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
左手拿着MOTOLOLA右手拿着NOKIA,要多潇洒,有多潇洒,哈哈,终于学会了,但是可能这个时候,又会有人不经意的拍拍肩膀对你说:哥们,别高兴的太早,你还是菜鸟,离学会还差着一大截呢!rss <?php
/*****************************************
* RSS2.0 Generator
* Create by MagicBoy(darasion)
* Copyright ? 奇异男孩
******************************************/
/*――――――――――――――――
利用办法:
将上面的数组,带入响应的函数。
1、频道主体
$channel = array(
title => '频道称号(必备)',
link => '频道的URL(必备)',
description => '频道的描写(必备)',
language => '频道文章所用言语(可选)',
webmaster => '担任频道手艺事务的网站办理员email(可选)',
managingEditor => '义务编纂的email(可选)',
pubDate => '频道内容宣布日期,格局遵守RFC822格局(年份可为2位或4位)(可选)',
lastBuildDate => '频道内容最初的修正日期(Sat, 07 Sep 2002 09:42:31 GMT)(可选)',
skipDays => '提醒旧事聚合器,那些天它可以跳过。(可选)',
copyright => '频道内容的版权申明(可选)',
ttl => '无效期,用以指明该频道可被缓存的最长工夫(可选)',
);
2、频道图片
$image = array(
url => '图片的链接(必备)',
title => '图片的题目,用于http的alt属性(必备)',
link => '网站的url(实践中常以频道的url取代)(必备)',
width => '图片的宽度(象素为单元)最大144,默许88(可选)',
height => '图片的高度(象素为单元)最大400,默许31(可选)',
description => '用于link的title属性(可选)'
);
3、频道项
$item = array(
title => '项(item)的题目(必备)',
description => '项的纲目(必备)',
link => '项的URL(必备)',
comments => '该项的评论(comments)页的URL(可选)',
guid => '1项的独一标记符串(可选)',
author => '该项作者的email(可选)',
enclosure => '描写该附带的媒体对象(可选)',
category => '包括该项的一个或几个分类(catogory)(可选)',
pubdate => '项的宣布工夫(可选)',
source_url => '该项来自的RSS道(可选)',
source_name => '该项来自的RSS道(可选)'
);
――――――――――――――――*/
class rss2
{
var $channel_pre="";
var $str_image="";
var $str_item="";
var $channel_end="";
/*机关函数*/
function rss2($channel,$encoding="GB2312")
{
$this->channel($channel,$encoding);
}
/*生成频道主体*/
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";//频道称号(必备)
$this->channel_pre.= " <link>".$channel['link']."</link>\n";//频道的URL(必备)
$this->channel_pre.= " <description>".$channel['description']."</description>\n";//频道的描写(必备)
$this->channel_pre.= " <generator>MagicBoy RSS Generator v1.0</generator>\n";//创立此文档的法式(可选)
if(isset($channel['language']))$this->channel_pre.= " <language>".$channel['language']."</language>\n";//频道文章所用言语(可选)
if(isset($channel['webmaster']))$this->channel_pre.= " <webMaster>".$channel['webmaster']."</webMaster>\n";//担任频道手艺事务的网站办理员email(可选)
if(isset($channel['managingeditor']))$this->channel_pre.= " <managingEditor>".$channel['managingeditor']."</managingEditor>\n";//义务编纂的email(可选)
if(isset($channel['pubdate']))$this->channel_pre.= " <pubDate>".$channel['pubdate']."</pubDate>\n";//频道内容宣布日期,格局遵守RFC822格局(年份可为2位或4位)(可选)
if(isset($channel['lastbuilddate']))$this->channel_pre.= " <lastBuildDate>".$channel['lastbuilddate']."</lastBuildDate>\n";//频道内容最初的修正日期(Sat, 07 Sep 2002 09:42:31 GMT)(可选)
if(isset($channel['skipdays']))$this->channel_pre.= " <skipDays>".$channel['skipdays']."</skipDays>\n";//提醒旧事聚合器,那些天它可以跳过。(可选)
if(isset($channel['copyright']))$this->channel_pre.= " <copyright>".$channel['copyright']."</copyright>\n";//频道内容的版权申明(可选)
if(isset($channel['ttl']))$this->channel_pre.= " <ttl>".$channel['ttl']."</ttl>\n";//无效期,用以指明该频道可被缓存的最长工夫(可选)
$this->channel_end.= " </channel>\n";
$this->channel_end.= "</rss>\n";
}
/*生成频道图片*/
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";//图片的url(必备)
if(isset($image['title']))$this->str_image.= " <title>".$image['title']."</title>\n";//图片的题目,用于http的alt属性(必备)
if(isset($image['link']))$this->str_image.= " <link>".$image['link']."</link>\n";//网站的url(实践中常以频道的url取代)(必备)
if(isset($image['width']))$this->str_image.= " <width>".$image['width']."</width>\n";//图片的宽度(象素为单元)最大144,默许88(可选)
if(isset($image['height']))$this->str_image.= " <height>".$image['height']."</height>\n";//图片的高度(象素为单元)最大400,默许31(可选)
if(isset($image['description']))$this->str_image.= " <description>".$image['description']."</description>\n";//用于link的title属性(可选)
$this->str_image.= " </image>\n";
}
/*频道项*/
function item($item)
{
$this->str_item.=" <item>\n";
$this->str_item.=" <title>".$item['title']."</title>\n";//项(item)的题目(必备)
$this->str_item.=" <description>".$item['description']."</description>\n";//项的纲目(必备)
$this->str_item.=" <link>".$item['link']."</link>\n";//项的URL(必备)
if(isset($item['comments']))$this->str_item.=" <comments>".$item['comments']."</comments>\n";//该项的评论(comments)页的URL(可选)
if(isset($item['guid']))$this->str_item.=" <guid>".$item['guid']."</guid>\n";//1项的独一标记符串(可选)
if(isset($item['author']))$this->str_item.=" <author>".$item['author']."</author>\n";//该项作者的email(可选)
if(isset($item['enclosure']))$this->str_item.=" <enclosure>".$item['enclosure']."</enclosure>\n";//描写该附带的媒体对象(可选)
if(isset($item['category']))$this->str_item.=" <category>".$item['category']."</category>\n";//包括该项的一个或几个分类(catogory)(可选)
if(isset($item['pubdate']))$this->str_item.=" <pubDate>".$item['pubdate']."</pubDate>\n";//项的宣布工夫(可选)
if(isset($item['source_url']))$this->str_item.=" <source url=\"".$item['source_url']."\">".$item['source_name']."</source>\n";//该项来自的RSS道(可选)
$this->str_item.=" </item>\n";
}
/*输入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;
}
}
/*擦除频道*/
function erase_channel()
{
unset($this->channel_pre);
unset($this->channel_end);
}
/*擦除频道图片*/
function erase_image()
{
unset($this->str_image);
}
/*擦除项目*/
function erase_item()
{
unset($this->str_item);
}
/*擦除一切*/
function erase()
{
$this->erase_channel();
$this->erase_image();
$this->erase_item();
}
}
?>
PHP于1994年由Rasmus Lerdorf创建,刚刚开始是Rasmus Lerdorf为了要维护个人网页而制作的一个简单的用Perl语言编写的程序。 |
|