php 生成RSS文件類案例代碼
發(fā)表時間:2023-08-01 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]RSS(簡易信息聚合):是一種消息來源格式規(guī)范,用以發(fā)布經(jīng)常更新數(shù)據(jù)的網(wǎng)站,例如博客文章、新聞、音頻或視頻的網(wǎng)摘。RSS文件(或稱做摘要、網(wǎng)絡(luò)摘要、或頻更新,提供到頻道)包含了全文或是節(jié)錄的文字,再...
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)頁或以桌面為
架構(gòu)的軟件來閱讀。標(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);
}
}
?>
以上就是php 生成RSS文件類實例代碼的詳細(xì)內(nèi)容,更多請關(guān)注php中文網(wǎng)其它相關(guān)文章!
學(xué)習(xí)教程快速掌握從入門到精通的SQL知識。