这篇文章主要介绍了PHP读取并输出XML文件数据的简单实现方法,涉及php针对xml格式文件数据的载入、遍历、读取、输出等相关操作技巧,需要的朋友可以参考下
本文实例讲述了PHP读取并输出XML文件数据的简单实现方法。分享给大家供大家参考,具体如下:
config.XML文件:
张明
1234567890@qq.com
一样菜
985931
王红
2345678901@qq.com
冰封
5625362
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."
";
}
?>
结果
张明: 1234567890@qq.com, 一样菜, 985931
王红: 2345678901@qq.com, 冰封, 5625362
PS:这里再为大家提供几款关于xml操作的在线工具供大家参考使用:
在线XML/JSON互相转换工具:http://tools.jb51.net/code/xmljson
在线格式化XML/在线压缩XML:http://tools.jb51.net/code/xmlformat
XML在线压缩/格式化工具:http://tools.jb51.net/code/xml_format_compress
XML代码在线格式化美化工具:http://tools.jb51.net/code/xmlcodeformat
您可能感兴趣的文章: