Meth | PHP读取XML文件数据 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 >[email protected]</ email >
         < username >一样菜</ username >
         < code >985931</ code >
     </ student >
     
     < student >
         < name >王红</ name >
         < email >[email protected]</ 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
张明: [email protected], 一样菜, 985931
王红: [email protected], 冰封, 5625362

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 >[email protected]</ email >
         < username >一样菜</ username >
         < code >985931</ code >
     </ student >
     
     < student >
         < name >王红</ name >
         < email >[email protected]</ 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
张明: [email protected], 一样菜, 985931
王红: [email protected], 冰封, 5625362

猜你喜欢

转载自www.cnblogs.com/PlusHappy/p/9854966.html