文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>rss生成类

rss生成类

时间:2006-01-23  来源:wleige


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 (
[email protected]
)
*  说明 : 你可使用它到任意地方,但请保留此信息
*  使用说明:
*  $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);
   }
}
?>


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载