/**<br>
* Class name: RSS<br>
* Author : LeadStar Team<br>
* website : <a href=”http://www.leadstar.com.cn/”><font color=”#2771B3″>http://www.leadstar.com.cn/</font></a><br>
* CopyRight : LeadStar Team<br>
*/<br>
if (defined(‘_CLASS_RSS_PHP’)) return;<br>
define(‘_CLASS_RSS_PHP’,1);</p>
<p>class RSS {<br>
//public<br>
var $rss_ver = “2.0”;<br>
var $channel_title = ”;<br>
var $channel_link = ”;<br>
var $channel_description = ”;<br>
var $language = ‘zh_CN’;<br>
var $copyright = ”;<br>
var $webMaster = ”;<br>
var $pubDate = ”;<br>
var $lastBuildDate = ”;<br>
var $generator = ‘RedFox RSS Generator’;</p>
<p> var $content = ”;<br>
var $items = array();</p>
<p> /**************************************************************************/<br>
// 函数名: RSS<br>
// 功能: 构造函数<br>
// 参数: $title<br>
// $link<br>
// $description<br>
/**************************************************************************/<br>
function RSS($title, $link, $description) {<br>
$this->channel_title = $title;<br>
$this->channel_link = $link;<br>
$this->channel_description = $description;<br>
$this->pubDate = Date(‘Y-m-d H:i:s’,time());<br>
$this->lastBuildDate = Date(‘Y-m-d H:i:s’,time());<br>
}<br>
/**************************************************************************/<br>
// 函数名: AddItem<br>
// 功能: 添加一个节点<br>
// 参数: $title<br>
// $link<br>
// $description $pubDate<br>
/**************************************************************************/<br>
function AddItem($title, $link, $description ,$pubDate) {<br>
$this->items[] = array(‘title’ => $title ,<br>
‘link’ => $link,<br>
‘description’ => $description,<br>
‘pubDate’ => $pubDate);<br>
}<br>
/**************************************************************************/<br>
// 函数名: BuildRSS<br>
// 功能: 生成rss xml文件内容<br>
/**************************************************************************/<br>
function BuildRSS() {<br>
$s = “<?xml version=’1.0′ encoding=’utf-8′?><br>
n<rss version=”2.0″>n”;<br>
// start channel<br>
$s .= “<channel>n”;<br>
$s .= “<title><![CDATA[{$this->channel_title}]]></title>n”;<br>
$s .= “<link><![CDATA[{$this->channel_link}]]></link>n”;<br>
$s .= “<description><![CDATA[{$this->channel_description}]]></description>n”;<br>
$s .= “<language>{$this->language}</language>n”;<br>
if (!empty($this->copyright)) {<br>
$s .= “<copyright><![CDATA[{$this->copyright}]]></copyright>n”;<br>
}<br>
if (!empty($this->webMaster)) {<br>
$s .= “<webMaster><![CDATA[{$this->webMaster}]]></webMaster>n”;<br>
}<br>
if (!empty($this->pubDate)) {<br>
$s .= “<pubDate>{$this->pubDate}</pubDate>n”;<br>
}</p>
<p> if (!empty($this->lastBuildDate)) {<br>
$s .= “<lastBuildDate>{$this->lastBuildDate}</lastBuildDate>n”;<br>
}</p>
<p> if (!empty($this->generator)) {<br>
$s .= “<generator>{$this->generator}</generator>n”;<br>
}<br>
// start items<br>
for ($i=0;$i<count($this->items);$i++) {<br>
$s .= “<item>n”;<br>
$s .= “<title><![CDATA[{$this->items[$i][‘title’]}]]></title>n”;<br>
$s .= “<link><![CDATA[{$this->items[$i][‘link’]}]]></link>n”;<br>
$s .= “<description><![CDATA[{$this->items[$i][‘description’]}]]></description>n”;<br>
$s .= “<pubDate>{$this->items[$i][‘pubDate’]}</pubDate>n”; <br>
$s .= “</item>n”;<br>
}<br>
// close channel<br>
$s .= “</channel>n</rss>”;<br>
$this->content = $s;<br>
}<br>
/**************************************************************************/<br>
// 函数名: Show<br>
// 功能: 将产生的rss内容直接打印输出<br>
/**************************************************************************/<br>
function Show() {<br>
if (empty($this->content)) $this->BuildRSS();<br>
echo($this->content);<br>
}<br>
/**************************************************************************/<br>
// 函数名: SaveToFile<br>
// 功能: 将产生的rss内容保存到文件<br>
// 参数: $fname 要保存的文件名<br>
/**************************************************************************/<br>
function SaveToFile($fname) {<br>
$handle = fopen($fname, ‘wb’);<br>
if ($handle === false) return false;<br>
fwrite($handle, $this->content);<br>
fclose($handle);<br>
}<br>
}<br>
?></p>
<p>feed.php代码:</p>
<p><?php<br>
require_once(‘RSS.php’);<br>
require_once(‘conn/connect.inc’);<br>
function changUTF($con){<br>
$con = iconv(“gb2312″,”utf-8”,$con);<br>
return $con;<br>
}<br>
$myRss = new RSS(“购房者杂志网”,”<a href=”http://zazhi.goufang.xn--com”><font color=”#2771B3″>http://zazhi.goufang.com”,”购房者杂志网”);</font></a><br>
//$myRss->RSS();<br>
$sql = “select ID,m_name,m_num,m_class,m_intro,m_time from m_property”;<br>
$result = mysql_query($sql, $connection);<br>
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {<br>
$sql1 = “select tag_con from m_tag where m_id=”.$row[‘ID’];<br>
$result1 = mysql_query($sql1,$connection);<br>
while ($row1 = mysql_fetch_array($result1, MYSQL_ASSOC)) {<br>
$tag = $tag.” “.$row[‘tag_con’];<br>
}<br>
$myRss->AddItem(changUTF($row[‘m_name’].$row[‘m_num’]),'<a href=”http://zazhi.goufang.com/html/'”><font color=”#2771B3″>http://zazhi.goufang.com/html/'</font></a>.$row[‘ID’].’.html’,changUTF($row1[‘$tag’].$row[‘m_intro’]),$row[‘m_time’]);<br>
}<br>
$myRss->BuildRSS();<br>
$myRss->SaveToFile(‘feed.rss’);<br>
?>
Class name: RSS
发布于 2009年2月6日
归档于 Other