This article mainly introduces the method of PHP to simply read xml files, involving PHP implementation techniques for xml file node operations. Friends in need can refer to the version number in
I will update the software version. The data information is stored in the xml file, and the version information is read out when used.
The content of the xml file is as follows:
v1.8.7
The following is how PHP reads the xml file
$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 ); } }
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
PHPMathematical operations and data processing example analysis_php skills
IntroductionPHPSome advanced usage of caching in the Yii framework_php skills
PHPSimple example of PDO operation_php skills
The above is the detailed content of PHP implements method of reading xml file. For more information, please follow other related articles on the PHP Chinese website!