zoukankan      html  css  js  c++  java
  • PHP将XML文件转换成PHP数组

    前提是有一个test.xml文件

    <?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);                                        
    ?>        

  • 相关阅读:
    4408: [Fjoi 2016]神秘数
    UOJ #35. 后缀排序[后缀数组详细整理]
    POJ 2887 Big String
    搜索过滤grep(win下为findstr)
    解决putty自动断开的问题
    > >> 将错误输出到文件
    环境变量
    端口被占用,查看并杀死占用端口的进程
    查找文件路径find
    【vim使用】
  • 原文地址:https://www.cnblogs.com/zcy_soft/p/1933940.html
Copyright © 2011-2022 走看看