This article mainly introduces the simple implementation method of PHP reading and outputting XML file data, involving PHP's loading, traversing, reading, output and other related operating skills for xml format file data. Friends in need can refer to it. I hope Can help everyone.
config.XML file:
<?xml version="1.0" encoding="UTF-8"?> <node> <student> <name>张明</name> <email>1234567890@qq.com</email> <username>一样菜</username> <code>985931</code> </student> <student> <name>王红</name> <email>2345678901@qq.com</email> <username>冰封</username> <code>5625362</code> </student> </node>
php file:
<?php $file = 'config/config.xml'; $xml_array=simplexml_load_file($file); //将XML中的数据,读取到数组对象中 foreach($xml_array as $tmp){ echo $tmp->name.": ".$tmp->email.", ".$tmp->username.", ".$tmp->code."<br>"; } ?>
Result
张明: 1234567890@qq.com, 一样菜, 985931 王红: 2345678901@qq.com, 冰封, 5625362
Related recommendations:
JQuery reads XML file data and displays the implementation code_jquery
JXTree object, read external xml file data, function to generate tree_javascript skills
The difference between XML and HTML
The above is the detailed content of Simple implementation of PHP reading and outputting XML file data. For more information, please follow other related articles on the PHP Chinese website!