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

  • 相关阅读:
    遇到一个php解析错误
    wndows netsh winsock reset
    javascript 阻塞
    ci 文件类型错误xlsx
    input限制整数
    canvas 时钟转动
    JS实现别踩白块游戏
    本地存储技术localStorage
    JavaScript事件
    JavaScript实现放大镜效果
  • 原文地址:https://www.cnblogs.com/zcy_soft/p/1933940.html
Copyright © 2011-2022 走看看