您的位置:首页 > 编程语言 > PHP开发

PHP读取XML文件数据

2016-06-12 00:27 441 查看
XML文件

<?xml version="1.0" encoding="UTF-8"?>
<node>
<student>
<name>张明</name>
<email>1187816874@qq.com</email>
<username>一样菜</username>
<code>985931</code>
</student>

<student>
<name>王红</name>
<email>2545125274@qq.com</email>
<username>冰封</username>
<code>5625362</code>
</student>
</node>


php

<?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>";
}
?>


结果

张明: 1187816874@qq.com, 一样菜, 985931
王红: 2545125274@qq.com, 冰封, 5625362
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: