PHP读取XML文件数据

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

 

posted @ 2016-06-12 00:27  一样菜  阅读(7683)  评论(0编辑  收藏  举报