Example of a simple method for PHP to read xml files, and an example for php to read xml files
This example describes how PHP simply reads xml files. We will share this with you for your reference. The details are as follows:
I store the version number and other data information in the software version update in the xml file, and read the version information during use.
The content of the xml file is as follows:
<xml version="v1.01" encoding="utf-8"> <updataMessages><version>v1.8.7</version> </updataMessages></xml>
The following describes how PHP reads xml files.
$ Doc = new DOMDocument (); $ filepath = $ _ SERVER ['document _ root']. "/upload/versionpc/ios. xml "; // xml file path $ 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: Here are some online tools for xml operations for your reference:
Online XML/JSON conversion tools:
Http://tools.jb51.net/code/xmljson
Online formatting XML/online compression XML:
Http://tools.jb51.net/code/xmlformat
XMLOnline compression/formatting tools:
Http://tools.jb51.net/code/xml_format_compress
XMLCode Online formatting and beautification tools:
Http://tools.jb51.net/code/xmlcodeformat