小編給大家分享一下利用xml實(shí)現(xiàn)rss訂閱的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

RSS是一種網(wǎng)頁(yè)內(nèi)容聯(lián)合格式,是XML的一種,所有的RSS文檔都遵循XML1.0規(guī)范。
具體示例:
<span style="font-family:Microsoft YaHei;font-size:18px;"><?xml version = "1.0" encoding = "utf-8" ?>
<rss version = "2.0" xmlns:wfw ="http://wellformedweb.org/CommentAPI/">
<channel>
<title>標(biāo)題</title>
<link>鏈接地址</link>
<description>描述</description>
<language>描述語(yǔ)言</language>
<copyright>版本</copyright>
<pubdate>時(shí)間</pubdate>
<item>
<title>日志標(biāo)題</title>
<link>日志的url訪問(wèn)地址</link>
<author>日志的作者</author>
<pubdate>日志的發(fā)布時(shí)間</pubdate>
<description>日志的內(nèi)容</description>
</item>
</channel>
</rss></span>此時(shí)應(yīng)該鏈接數(shù)據(jù)庫(kù),輸出想要的結(jié)果。
Test.PHP
<span style="font-family:Microsoft YaHei;font-size:18px;"><?PHP
include("./conn.php");
class test{
public $title = '';
public $link = '';
public $description= '';
public $items = '';
public $template ='./test.xml';
public $dom = '';
public $rss = '';
public function__construct(){
$this ->dom = new domDocument('1.0','utf-8');
$this ->dom -> load($this -> template);
$this ->rss = $this -> dom -> GetElementsByTagName('rss');
}
public functioncreateChannel(){
$channel =$this -> dom -> createElement("channel");
$channel-> appendChild($this -> createEle('title',$this -> title));
$channel-> appendChild($this -> createEle('link',$this -> link));
$channel-> appendChild($this -> createEle('description',$this ->description));
$this ->rss -> appendChild($channel);
}
public functioncreateEle($name,$value){
$element =$this -> dom -> createElement($name);
$text = $this-> dom -> createTextNode($value);
$element-> appendChild($text);
return$element;
}
protected functionadditem($list){
foreach($listas $goods){
$this-> rss -> appendChild($this-> createitem($goods));
}
}
public functioncreateitem($arr){
$item = $this-> dom -> createElement("item");
foreach($arras $key => $value){
$item-> appendChild($this -> createEle($key,$value));
}
return $item;
}
public functiondisplay(){
$this ->createChannel();
$this ->additem($this -> items);
echo $this-> dom -> savexml();
}
}
$sql = "select * fromstu";
$rs = mysql_query($sql);
while($row =mysql_fetch_assoc($rs)){
$list[] = $row;
}
$test = new test();
$test -> title = "測(cè)試標(biāo)題";
$test -> link = "測(cè)試連接";
$test -> description ="測(cè)試內(nèi)容";
$test -> display();
$test -> items = $list;
</span>看完了這篇文章,相信你對(duì)利用xml實(shí)現(xiàn)rss訂閱的方法有了一定的了解,想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
當(dāng)前標(biāo)題:利用xml實(shí)現(xiàn)rss訂閱的方法-創(chuàng)新互聯(lián)
文章出自:http://chinadenli.net/article10/pgdgo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷(xiāo)型網(wǎng)站建設(shè)、建站公司、網(wǎng)站建設(shè)、全網(wǎng)營(yíng)銷(xiāo)推廣、電子商務(wù)、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容