PHP provides a simple implementation method for reading and outputting XML file data.
This example describes how to use PHP to read and output XML file data. We will share this with you for your reference. The details are as follows:
Config. XML file:
<? Xml version = "1.0" encoding = "UTF-8"?> <Node> <student> <name> Zhang Ming </name> <email> 1234567890@qq.com </email> <username> same dish </username> <code> 985931 </code> </student> <name> Wang Hong </name> <email> 2345678901@qq.com </email> <username> ICE </username> <code> 5625362 </code> </ student> </node>
PHP file:
<? Php $ file = 'config/config. xml'; $ xml_array = simplexml_load_file ($ file); // read the data in xml to the array object foreach ($ xml_array as $ tmp) {echo $ tmp-> name. ":". $ tmp-> email. ",". $ tmp-> username. ",". $ tmp-> code. "<br>" ;}?>
Result
Zhang Ming: 1234567890@qq.com, same dish, 985931 Wang Hong: 2345678901@qq.com, ice, 5625362
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