rss(簡易信息聚合):是一種消息來源格式規(guī)范,用以發(fā)布經(jīng)常更新數(shù)據(jù)的網(wǎng)站,例如博客文章、新聞、音頻或音頻的網(wǎng)摘。rss文件(或稱做音頻、網(wǎng)絡(luò)摘要、或頻更新,提供到頻道)包含了全文或是節(jié)錄的文字,再加上發(fā)用者所訂閱之網(wǎng)摘布數(shù)據(jù)和授權(quán)的元數(shù)據(jù)。網(wǎng)絡(luò)摘要能夠使發(fā)行者自動地發(fā)布他們的數(shù)據(jù),同時也使讀者能更夠定期更新他們喜歡的網(wǎng)站或是聚合不同網(wǎng)站的網(wǎng)摘。rss摘要可以借由rss閱讀器、feed reader或是aggregator等網(wǎng)頁或以桌面為音頻的軟件來閱讀。標(biāo)準(zhǔn)的xml檔式可允許信息在一次發(fā)布后通過不同的程序閱覽。用戶借由將網(wǎng)摘輸入rss閱讀器或是用鼠標(biāo)點取瀏覽器上指向訂閱程序的rss小圖標(biāo)之uri(非通常稱為url)來訂閱網(wǎng)摘。rss閱讀器定期檢閱是否有更新,然后下載給監(jiān)看用戶界面。
RSS可以是以下三種解釋中任一種的縮寫,但其實這三者都是指同一種聯(lián)合供稿(Syndication)的技術(shù):
這篇文章主要介紹了PHP生成RSS文件類,可實現(xiàn)PHP生成RSS文件的功能,對于網(wǎng)站建設(shè)與優(yōu)化來說具有一定的實用價值,需要的朋友可以參考下
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);? ???}? }? ?>