This article describes a simple implementation method for PHP to read and output XML file data. Share it for your reference, as follows:
document:
<?xml version="1.0" encoding="UTF-8"?> <node> <student> <name>Zhang Ming</name> <email>1234567890@</email> <username>The same dish</username> <code>985931</code> </student> <student> <name>Wang Hong</name> <email>2345678901@</email> <username>Ice seal</username> <code>5625362</code> </student> </node>
php file:
<?php $file = 'config/'; $xml_array=simplexml_load_file($file); //Read the data in XML into the array object foreach($xml_array as $tmp){ echo $tmp->name.": ".$tmp->email.", ".$tmp->username.", ".$tmp->code."<br>"; } ?>
result
Zhang Ming: 1234567890@, The same dish, 985931 Wang Hong: 2345678901@, Ice seal, 5625362
PS: Here are a few online tools for your reference:
OnlineXML/JSON mutual conversion tool:
http://tools./code/xmljson
Online formattingXML/Online compressionXML:
http://tools./code/xmlformat
XMLOnline compression/formatting tools:
http://tools./code/xml_format_compress
XMLCode online formatting and beautification tools:
http://tools./code/xmlcodeformat
For more information about PHP related content, please check out the topic of this site:Summary of PHP's XML file operation skills》、《Complete collection of PHP array (Array) operation techniques》、《Summary of usage of php strings》、《Summary of PHP error and exception handling methods》、《Introduction to PHP basic syntax》、《PHP object-oriented programming tutorial》、《PHP+mysql database operation tutorial"and"Summary of common database operation techniques for php》
I hope this article will be helpful to everyone's PHP programming.