Meth | PHP读取XML文件数据

PHP读取XML文件数据

 

XML文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?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

1
2
3
4
5
6
7
<?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>";
    
?>

 结果

1
2
张明: 1187816874@qq.com, 一样菜, 985931
王红: 2545125274@qq.com, 冰封, 5625362
原文地址:https://www.cnblogs.com/paulycoding/p/9854966.html