本文實(shí)例講述了PHP讀取并輸出XML文件數(shù)據(jù)的簡(jiǎn)單實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
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中的數(shù)據(jù),讀取到數(shù)組對(duì)象中
foreach($xml_array as $tmp){
echo $tmp->name.": ".$tmp->email.", ".$tmp->username.", ".$tmp->code."<br>";
}
?>
結(jié)果
張明: 1234567890@qq.com, 一樣菜, 985931
王紅: 2345678901@qq.com, 冰封, 5625362
PS:這里再為大家提供幾款關(guān)于xml操作的在線工具供大家參考使用:
在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.html5code.net/code/xmljson
在線格式化XML/在線壓縮XML:
http://tools.html5code.net/code/xmlformat
XML在線壓縮/格式化工具:
http://tools.html5code.net/code/xml_format_compress
XML代碼在線格式化美化工具:
http://tools.html5code.net/code/xmlcodeformat
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP針對(duì)XML文件操作技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP錯(cuò)誤與異常處理方法總結(jié)》、《PHP基本語(yǔ)法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!