本文實例講述了PHP讀取并輸出XML文件數據的簡單實現方法。分享給大家供大家參考,具體如下:
config.XML文件:
<?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文件:
<?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>"; }?>
結果
張明: 1234567890@qq.com, 一樣菜, 985931王紅: 2345678901@qq.com, 冰封, 5625362
希望本文所述對大家PHP程序設計有所幫助。
新聞熱點
疑難解答
圖片精選