作者:赵博钧石博 | 来源:互联网 | 2017-05-14 02:24
RSS是一种网页内容联合格式,是XML的一种,所有的RSS文档都遵循XML1.0规范。
具体示例:
链接地址
描述
描述语言
版本
时间
-
日志的url访问地址
日志的作者
日志的发布时间
日志的内容
此时应该链接数据库,输出想要的结果。
Test.PHP
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;
以上就是利用xml实现rss订阅的详细内容,更多请关注 第一PHP社区 其它相关文章!