rss(簡易信息聚合):是一種消息來源格式規范,用以發布經常更新數據的網站,例如博客文章、新聞、音頻或音頻的網摘。rss文件(或稱做音頻、網絡摘要、或頻更新,提供到頻道)包含了全文或是節錄的文字,再加上發用者所訂閱之網摘布數據和授權的元數據。網絡摘要能夠使發行者自動地發布他們的數據,同時也使讀者能更夠定期更新他們喜歡的網站或是聚合不同網站的網摘。rss摘要可以借由rss閱讀器、feed reader或是aggregator等網頁或以桌面為音頻的軟件來閱讀。標準的xml檔式可允許信息在一次發布后通過不同的程序閱覽。用戶借由將網摘輸入rss閱讀器或是用鼠標點取瀏覽器上指向訂閱程序的rss小圖標之uri(非通常稱為url)來訂閱網摘。rss閱讀器定期檢閱是否有更新,然后下載給監看用戶界面。
RSS可以是以下三種解釋中任一種的縮寫,但其實這三者都是指同一種聯合供稿(Syndication)的技術:
這篇文章主要介紹了PHP生成RSS文件類,可實現PHP生成RSS文件的功能,對于網站建設與優化來說具有一定的實用價值,需要的朋友可以參考下
PHP RSS 生成類實例代碼如下:
?代碼如下:
<?php if (defined('_class_rss_php')) return; define('_class_rss_php教程',1); 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?=?"<!--l version="1.0" encoding="gb2312"-->?";? ???????//?start?channel? ???????$s?.=?"?";? ???????$s?.=?"?"? ???????$s?.=?"<link>{$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?.=?"<link>{$this->items[$i]['link']}?";? ???????????$s?.=?"<!--data[{$thi-->items[$i]['description']}]]>?";? ???????????$s?.=?"{$this->items[$i]['pubdate']}?";??????????? ???????????$s?.=?"?";? ???????}? ?????? ??????//?close?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 END