RSS is a web content syndication format and a type of XML. All RSS documents follow the XML1.0 specification.
Specific example:
<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>标题</title> <link>链接地址</link> <description>描述</description> <language>描述语言</language> <copyright>版本</copyright> <pubdate>时间</pubdate> <item> <title>日志标题</title> <link>日志的url访问地址</link> <author>日志的作者</author> <pubdate>日志的发布时间</pubdate> <description>日志的内容</description> </item> </channel> </rss></span>
At this time, you should connect to the database and output the desired results.
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 = "测试标题"; $test -> link = "测试连接"; $test -> description ="测试内容"; $test -> display(); $test -> items = $list; </span>
The above is the detailed content of Use xml to implement rss subscription. For more information, please follow other related articles on the PHP Chinese website!