文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>PHP将XML文件转换成PHP数组

PHP将XML文件转换成PHP数组

时间:2011-01-12  来源:春哥也编程

<?php                                                    
$s=join("",file('test.xml'));                         
$result = xml_to_array($s);                              
                                                         
function xml_to_array($xml)                              
{                                                        
  $array = (array)(simplexml_load_string($xml));         
  foreach ($array as $key=>$item){                       
    $array[$key]  =  struct_to_array((array)$item);      
  }                                                      
  return $array;                                         
}                                                        
function struct_to_array($item) {                        
  if(!is_string($item)) {                                
    $item = (array)$item;                                
    foreach ($item as $key=>$val){                       
      $item[$key]  =  struct_to_array($val);             
    }                                                    
  }                                                      
  return $item;                                          
}                                                        
print_r($result);                                        
?>        

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载