php rss源,php rss订阅

RSS类

/**

* Class name: RSS

*/

class RSS {

//public

var $rss_ver = "2.0";

var $channel_title = '';

var $channel_link = '';

var $channel_descrīption = '';

var $language = 'zh_CN';

var $copyright = '';

var $webMaster = '';

var $pubDate = '';

var $lastBuildDate = '';

var $generator = 'RedFox RSS Generator';

var $content = '';

var $items = array();

/**************************************************************************/

// 函数名: RSS

// 功能: 构造函数

// 参数: $title

// $link

// $descrīption

/**************************************************************************/

function RSS($title, $link, $descrīption) {

$this->channel_title = $title;

$this->channel_link = $link;

$this->channel_descrīption = $descrīption;

$this->pubDate = Date('Y-m-d H:i:s',time());

$this->lastBuildDate = Date('Y-m-d H:i:s',time());

}

/**************************************************************************/

// 函数名: AddItem

// 功能: 添加一个节点

// 参数: $title

// $link

// $descrīption $pubDate

/**************************************************************************/

function AddItem($title, $link, $descrīption ,$pubDate) {

$this->items[] = array('title' => $title ,'link' => $link,'descrīption' => $descrīption,'pubDate' => $pubDate);

}

/**************************************************************************/

// 函数名: BuildRSS

// 功能: 生成rss xml文件内容

/**************************************************************************/

function BuildRSS() {

$s = "<?xml version='1.0' encoding='utf-8'?>\n\n";

// start channel

$s .= "\n";

$s .= "

channel_title}]]>\n";

$s .= "channel_link}]]>\n";

$s .= "channel_descrīption}]]>\n";

$s .= "{$this->language}\n";

if (!empty($this->copyright)) {

$s .= "copyright}]]>\n";

}

if (!empty($this->webMaster)) {

$s .= "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 .= "

items[$i]['title']}]]>\n";

$s .= "items[$i]['link']}]]>\n";

$s .= "items[$i]['descrīption']}]]>\n";

$s .= "{$this->items[$i]['pubDate']}\n";

$s .= "\n";

}

// close channel

$s .= "\n";

$this->content = $s;

}

/**************************************************************************/

// 函数名: Show

// 功能: 将产生的rss内容直接打印输出

/**************************************************************************/

function Show() {

if (empty($this->content)) $this->BuildRSS();

echo($this->content);

}

/**************************************************************************/

// 函数名: SaveToFile

// 功能: 将产生的rss内容保存到文件

// 参数: $fname 要保存的文件名

/**************************************************************************/

function SaveToFile($fname) {

$handle = fopen($fname, 'wb');

if ($handle === false) return false;

fwrite($handle, $this->content);

fclose($handle);

}

function getFile($fname) {

$handle = fopen($fname, 'r');

if ($handle === false) return false;

while(!feof($handle)){

echo fgets($handle);

}

fclose($handle);

}

}

?> $result为从数据库中查询出来的值

foreach($result as $row) {

$rss->AddItem('标题','链接地址','描述','发布时间');

//具体参数根据上面的php类调整,这里仅作示例

}

$rss->RSS('','','');

$rss->BuildRSS();

$rss->SaveToFile('rss.xml');

$rss->getFile('rss.xml');

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值