Example of a simple method for PHP to read xml files, and an example for php to read xml files

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.