分享一个解析XML成为php数组的方法

<?php

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

$xml = 'site_1.xml';

        $myxml = simplexml_load_file($xml);

       // print_r($myxml);

       

   

        print_r(xmlToArray($myxml));

   

    function xmlToArray($xml){

       $arr_xml = (array)$xml;

       foreach($arr_xml as $key=>$item){

           if(is_object($item) || is_array($item)){

               $arr_xml[$key] = xmlToArray($item);

           }

       }

       return $arr_xml;

   }

   

?>

  

你可能感兴趣的:(解析xml)