宝哥软件园

php制作基于可扩展标记语言的简易资讯聚合订阅源功能示例

编辑:宝哥软件园 来源:互联网 时间:2021-09-06

本文实例讲述了服务器端编程语言(专业超文本预处理器的缩写)制作基于可扩展标记语言的简易资讯聚合订阅源功能。分享给大家供大家参考,具体如下:

首先制作一个简易资讯聚合模板,模板的文件名是feed.xml,代码如下:

?可扩展标记语言版本='1.0 '编码='utf-8 '?简易资讯聚合版本=' 2.0 ' xmlns : wfw=' http://格式良好的web。org/comment tapi/'/RSS再就是用服务器端编程语言(专业超文本预处理器的缩写)文件从数据库读取数据并生成简易资讯聚合文件,这里用一个数组模拟从数据库读取的数据:

?服务器端编程语言(Professional Hypertext Preprocessor的缩写)类Rss { protected $ dom=null受保护的$temp=' ./feed。XML ';受保护的$ rss=null受保护的$ title=受保护的$ desc=' ';受保护的$ link=public function _ _ construct(){ $ this-title='物理学;$这个-desc='现代物理学;$ this-link=' http://MySQL/RSS。PHP ';$this-dom=new DOMDocument('1.0 ',' utf-8 ');$ this-DOM-load($ this-temp);$ this-RSS=$ this-DOM-getElementsByTagName(' RSS ')-item(0);}公共函数feed($ arr){ $ this-createChannel();$ channel=$ this-DOM-getElementsByTagName(' channel ')-item(0);foreach($ arr as $ v){ $ channel-appendChild($ this-createItem($ v));}标题(“内容类型:文本/XML”);echo $ this-DOM-save XML();}受保护函数create channel(){ $ channel=$ this-DOM-create元素(' channel ');$ channel-appendChild($ this-createEle(' title ',$ this-title));$ channel-appendChild($ this-createEle(' link ',$ this-link));$ channel-appendChild($ this-createEle(' description ',$ this-desc));$ this-RSS-appendChild($ channel);}受保护的函数createItem($ arr){ $ item=$ this-DOM-create元素(' item ');foreach($ arr as $ k=$ v){ $ item-appendChild($ this-createEle($ k,$ v));}退回$ item}受保护函数createEle($name,$ value){ $ e=$ this-DOM-create element($ name);$ t=$ this-DOM-createTextNode($ value);$ e-appendChild($ t);返回$ e;}}$arr=array(array('title'='牛顿力学,' link'='1 ',' description'='牛顿力学),数组(' title'='相对论,' link'='1 ',' description'='爱因斯坦的相对论' ));$rss=新的Rss$ RSS-feed($ arr);最后在火狐下效果:

PS:这里再为大家提供几款关于可扩展标记语言操作的在线工具供大家参考使用:

在线XML/JSON互相转换工具:http://工具。JB 51。net/code/xmljson

在线格式化XML/在线压缩XML:http://工具。JB 51。net/代码/XML格式

可扩展置标语言在线压缩/格式化工具:http://工具。JB 51。net/code/XML _ format _ compress

可扩展置标语言代码在线格式化美化工具:http://工具。JB 51。net/code/xmlcodeformat

更多关于服务器端编程语言(专业超文本预处理器的缩写)相关内容感兴趣的读者可查看本站专题: 《PHP针对XML文件操作技巧总结》 、 《PHP数组(Array)操作技巧大全》 、 《php字符串(string)用法总结》 、 《PHP错误与异常处理方法总结》 、 《PHP基本语法入门教程》 、 《php面向对象程序设计入门教程》 、 《php+mysql数据库操作入门教程》 及《php常见数据库操作技巧汇总》

希望本文所述对大家服务器端编程语言(专业超文本预处理器的缩写)程序设计有所帮助。

更多资讯
游戏推荐
更多+