This article mainly introduces the PHP read and output XML file data simple implementation method, involving PHP for XML format file data loading, traversal, reading, output and other related operations skills, the need for friends can refer to the next
In this paper, a simple implementation method of PHP reading and outputting XML file data is described. Share to everyone for your reference, 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 dishes </username> <code> 985931</code> </student> <student> <name> Hong Hong </name> <email> 2345678901@qq.com</email> <username> ice </username> <code>5625362</code> </student></node>
PHP Files:
<?php $file = ' config/config.xml '; $xml _array=simplexml_load_file ($file); Reads the data from the XML into the array object in the foreach ($xml _array as $tmp) { echo $tmp->name. ":". $tmp->email. ",". $tmp Username. ",". $tmp->code. " <br> "; }? >
Results
Zhang Ming: 1234567890@qq.com, same dish, 985931 Wang Hong: 2345678901@qq.com, Frozen, 5625362
PS: Here are a few more online tools for you to refer to using XML operations:
Online XML/json Mutual Conversion Tool:
Http://tools.jb51.net/code/xmljson
Online formatting of XML/Online compressed XML:
Http://tools.jb51.net/code/xmlformat
XML Online Compression/formatting tools:
Http://tools.jb51.net/code/xml_format_compress
XML Code online format Beautification tool:
Http://tools.jb51.net/code/xmlcodeformat
Articles you may be interested in:
THINKPHP5 How to load static resource paths and constants
A brief analysis of the closure and anonymous function interpretation in PHP
Source Analysis Laravel The reason for repeating the same queue task