免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1166 | 回复: 0
打印 上一主题 下一主题

rss生成类 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-01-23 17:37 |只看该作者 |倒序浏览

if (defined('_CLASS_RSS_PHP')) return;
define('_CLASS_RSS_PHP',1);
/**
*  Class name: RSS
*  Author    : RedFox
*  website   : http://www.foxbat.cn/
*  blog      : http://redsoft.yculblog.com/
*  CopyRight : RedFox (
singlecat@163.com
)
*  说明 : 你可使用它到任意地方,但请保留此信息
*  使用说明:
*  $rss = new RSS('RedFox','http://redsoft.yculblog.com/',"RedFox's Blog");
*  $rss->AddItem('RSS Class',"
http://www.xxx.com","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 = "\n \n";
       // start channel
       $s .= "\n";
       $s .= "{$this->channel_title}\n"
       $s .= "{$this->channel_link}\n";
       $s .= "{$this->channel_description}\n";
       $s .= "{$this->language}\n";
       if (!empty($this->copyright)) {
          $s .= "{$this->copyright}\n";
       }
       if (!empty($this->webMaster)) {
          $s .= "{$this->webMaster}\n";
       }
       if (!empty($this->pubDate)) {
          $s .= "{$this->pubDate}\n";
       }
       if (!empty($this->lastBuildDate)) {
          $s .= "{$this->lastBuildDate}\n";
       }
       if (!empty($this->generator)) {
          $s .= "{$this->generator}\n";
       }
      
       // start items
       for ($i=0;$iitems),$i++) {
           $s .= "\n";
           $s .= "{$this->items[$i]['title']}\n";
           $s .= "{$this->items[$i]['link']}\n";
           $s .= "items[$i]['description']}]]>\n";
           $s .= "{$this->items[$i]['pubDate']}\n";           
           $s .= "\n";
       }
      
      // close channel
      $s .= "\n";
      $this->content = $s;
   }
   function Show() {
       if (empty($this->content)) $this->BuildRSS();
       header('Content-type:text/xml');
       echo($this->content);
   }
   function SaveToFile($fname) {
       if (empty($this->content)) $this->BuildRSS();
       $handle = fopen($fname, 'wb');
       if ($handle === false)  return false;
       fwrite($handle, $this->content);
       fclose($handle);
   }
}
?>


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/13004/showart_70102.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP