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

PHP读取并输出XML文件数据的简单实现方法

2017-12-22 13:57 1111 查看

本文实例讲述了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

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

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP针对XML文件操作技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP错误与异常处理方法总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家PHP程序设计有所帮助。

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  PHP XML
相关文章推荐