RSS是一种网页内容联合格式,是XML的一种,所有的RSS文档都遵循XML1.0规范。

具体示例:

<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>

此时应该链接数据库,输出想要的结果。

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>

以上就是利用xml实现rss订阅的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

  • 相关标签:xml,rss
  • 程序员必备接口测试调试工具:点击使用

    Apipost = Postman + Swagger + Mock + Jmeter

    Api设计、调试、文档、自动化测试工具

    网页生成APP,用做网站的技术去做APP:立即创建

    手机网站开发APP、自助封装APP、200+原生模块、2000+映射JS接口按需打包

    • 上一篇:四种获取RSS源xml文件的方法
    • 下一篇:怎样让Asp与XML交互

    相关文章

    相关视频


    • 使用xmlhttp为网站增加域名查询功能的示例代码...
    • 四种XML解析方式详解
    • 基于PHP对XML的操作详解
    • XML和Tomcat的入门知识的详细介绍
    • 利用xml实现rss订阅
    • Vue3 事件修饰符
    • vue3 指令
    • vue3 基础语法
    • vue3 组合api和选项api介绍

    视频教程分类

    • php视频教程
    • html视频教程
    • css视频教程
    • JS视频教程
    • jQuery视频教程
    • mysql视频教程
    • Linux视频教程
    • Python视频教程
    • Laravel视频教程
    • Vue视频教程

    专题

    利用xml实现rss订阅