源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP简单读取xml文件的方法示例

  • 时间:2020-11-04 19:44 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP简单读取xml文件的方法示例
本文实例讲述了PHP简单读取xml文件的方法。分享给大家供大家参考,具体如下: 我将软件版本更新中的版本号等数据信息存放在xml文件中,使用时将版本信息读取出来。 xml文件内容如下:
<xml version="v1.01" encoding="utf-8">
 <updataMessages>
<version>v1.8.7</version>
 </updataMessages>
</xml>

下面是PHP如何读取xml文件
$doc = new DOMDocument();
$filepath=$_SERVER['DOCUMENT_ROOT']."/upload/versionpc/ios.xml"; //xml文件路径
$doc->load($filepath);
$books = $doc->getElementsByTagName("updataMessages");
foreach( $books as $book )
{
$versions = $book->getElementsByTagName("version");
$version = $versions->item(0)->nodeValue;
$newmsgs = $book->getElementsByTagName("newmsg");
$newmsg = $newmsgs->item(0)->nodeValue;
if($version2==$version)
{
$return = array(
"status"=>0,
"msg"=>"success"
);
}
else
{
$return = array(
"status"=>2,
"msg"=>"have new version",
"data"=>$newmsg
);
}
}

[b]PS:这里再为大家提供几款关于xml操作的在线工具供大家参考使用:[/b] [b]在线XML/JSON互相转换工具: [/b][url=http://tools.jb51.net/code/xmljson]http://tools.jb51.net/code/xmljson[/url] [b]在线格式化XML/在线压缩XML: [/b][url=http://tools.jb51.net/code/xmlformat]http://tools.jb51.net/code/xmlformat[/url] [b]XML[/b][b]在线压缩/格式化工具: [/b][url=http://tools.jb51.net/code/xml_format_compress]http://tools.jb51.net/code/xml_format_compress[/url] [b]XML[/b][b]代码在线格式化美化工具: [/b][url=http://tools.jb51.net/code/xmlcodeformat]http://tools.jb51.net/code/xmlcodeformat[/url] 更多关于PHP相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/234.htm]PHP针对XML文件操作技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/623.htm]PHP数组(Array)操作技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》、《[url=http://www.1sucai.cn/Special/196.htm]PHP错误与异常处理方法总结[/url]》、《[url=http://www.1sucai.cn/Special/348.htm]PHP基本语法入门教程[/url]》、《[url=http://www.1sucai.cn/Special/43.htm]php面向对象程序设计入门教程[/url]》、《[url=http://www.1sucai.cn/Special/84.htm]php+mysql数据库操作入门教程[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部