php 生成RSS文件類實例代碼

rss(簡易信息聚合):是一種消息來源格式規范,用以發布經常更新數據的網站,例如博客文章、新聞、音頻音頻的網摘。rss文件(或稱做音頻、網絡摘要、或頻更新,提供到頻道)包含了全文或是節錄的文字,再加上發用者所訂閱之網摘布數據和授權的元數據。網絡摘要能夠使發行者自動地發布他們的數據,同時也使讀者能更夠定期更新他們喜歡的網站或是聚合不同網站的網摘。rss摘要可以借由rss閱讀器、feed reader或是aggregator等網頁或以桌面為音頻的軟件來閱讀。標準的xml檔式可允許信息在一次發布后通過不同的程序閱覽。用戶借由將網摘輸入rss閱讀器或是用鼠標點取瀏覽器上指向訂閱程序的rss小圖標之uri(非通常稱為url)來訂閱網摘。rss閱讀器定期檢閱是否有更新,然后下載給監看用戶界面。

RSS可以是以下三種解釋中任一種的縮寫,但其實這三者都是指同一種聯合供稿(Syndication)的技術:

這篇文章主要介紹了PHP生成RSS文件類,可實現PHP生成RSS文件的功能,對于網站建設與優化來說具有一定的實用價值,需要的朋友可以參考下

PHP RSS 生成類實例代碼如下:

?代碼如下:

<?php    if (defined(&#39;_class_rss_php&#39;)) return;   define(&#39;_class_rss_php教程&#39;,1);     class rss {      //public      $rss_ver = "2.0";      $channel_title = &#39;&#39;;      $channel_link = &#39;&#39;;      $channel_description = &#39;&#39;;      $language = &#39;zh_cn&#39;;      $copyright = &#39;&#39;;      $webmaster = &#39;&#39;;      $pubdate = &#39;&#39;;      $lastbuilddate = &#39;&#39;;      $generator = &#39;redfox rss generator&#39;;         $content = &#39;&#39;;      $items = array();         function rss($title, $link, $description) {          $this->channel_title?=?$title;?  ???????$this-&gt;channel_link?=?$link;?  ???????$this-&gt;channel_description?=?$description;?  ???????$this-&gt;pubdate?=?date('y-m-d?h:i:s',time());?  ???????$this-&gt;lastbuilddate?=?date('y-m-d?h:i:s',time());?  ???}?  ?  ???function?additem($title,?$link,?$description?,$pubdate)?{?  ???????$this-&gt;items[]?=?array('titile'?=&gt;?$title?,?  ????????????????????????'link'?=&gt;?$link,?  ????????????????????????'description'?=&gt;?$description,?  ????????????????????????'pubdate'?=&gt;?$pubdate);?  ???}?  ?  ???function?buildrss()?{?  ???????$s?=?"<!--l version="1.0" encoding="gb2312"-->?";?  ???????//?start?channel?  ???????$s?.=?"?";?  ???????$s?.=?"?"?  ???????$s?.=?"<link>{$this-&gt;channel_link}?";?  ???????$s?.=?"{$this-&gt;channel_description}?";?  ???????$s?.=?"{$this-&gt;language}?";?  ???????if?(!emptyempty($this-&gt;copyright))?{?  ??????????$s?.=?"{$this-&gt;copyright}?";?  ???????}?  ???????if?(!emptyempty($this-&gt;webmaster))?{?  ??????????$s?.=?"{$this-&gt;webmaster}?";?  ???????}?  ???????if?(!emptyempty($this-&gt;pubdate))?{?  ??????????$s?.=?"{$this-&gt;pubdate}?";?  ???????}?  ?  ???????if?(!emptyempty($this-&gt;lastbuilddate))?{?  ??????????$s?.=?"{$this-&gt;lastbuilddate}?";?  ???????}?  ?  ???????if?(!emptyempty($this-&gt;generator))?{?  ??????????$s?.=?"{$this-&gt;generator}?";?  ???????}?  ???????  ???????//?start?items?  ???????for?($i=0;$iitems),$i++)?{?  ???????????$s?.=?"?";?  ???????????$s?.=?"?";?  ???????????$s?.=?"<link>{$this-&gt;items[$i]['link']}?";?  ???????????$s?.=?"<!--data[{$thi-->items[$i]['description']}]]&gt;?";?  ???????????$s?.=?"{$this-&gt;items[$i]['pubdate']}?";???????????  ???????????$s?.=?"?";?  ???????}?  ??????  ??????//?close?channel?  ??????$s?.=?"?";?  ??????$this-&gt;content?=?$s;?  ???}?  ?  ???function?show()?{?  ???????if?(emptyempty($this-&gt;content))?$this-&gt;buildrss();?  ???????header('content-type:text/xml');?  ???????echo($this-&gt;content);?  ???}?  ?  ???function?savetofile($fname)?{?  ???????if?(emptyempty($this-&gt;content))?$this-&gt;buildrss();?  ???????$handle?=?fopen($fname,?'wb');?  ???????if?($handle?===?false)??return?false;?  ???????fwrite($handle,?$this-&gt;content);?  ???????fclose($handle);?  ???}?  }?  ?&gt;

? 版權聲明
THE END
喜歡就支持一下吧
點贊12 分享