欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP簡(jiǎn)單讀取xml文件的方法示例

 更新時(shí)間:2017年04月20日 10:58:57   作者:momo_mutou  
這篇文章主要介紹了PHP簡(jiǎn)單讀取xml文件的方法,涉及php針對(duì)xml文件節(jié)點(diǎn)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了PHP簡(jiǎn)單讀取xml文件的方法。分享給大家供大家參考,具體如下:

我將軟件版本更新中的版本號(hào)等數(shù)據(jù)信息存放在xml文件中,使用時(shí)將版本信息讀取出來。

xml文件內(nèi)容如下:

<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
);
}
}

PS:這里再為大家提供幾款關(guān)于xml操作的在線工具供大家參考使用:

在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson

在線格式化XML/在線壓縮XML
http://tools.jb51.net/code/xmlformat

XML在線壓縮/格式化工具:
http://tools.jb51.net/code/xml_format_compress

XML代碼在線格式化美化工具:
http://tools.jb51.net/code/xmlcodeformat

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP針對(duì)XML文件操作技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP錯(cuò)誤與異常處理方法總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論