php十行代码将xml转成数组

<?php
header("Content-Type:text/html;charset=utf-8");
function xml2array($filename){ 
$xml = @simplexml_load_file($filename); 
//返回数组 
if(is_object($xml)){ 
$xml = json_encode($xml); 
$xml = json_decode($xml, true); 
} 
if(!is_array($xml)) $xml = null; 
return $xml; 
}

$path = 'f.xml';
echo '<pre>';
var_dump(xml2array($path));



?>

 

posted @ 2016-02-03 08:59  侠岚之弋痕夕  阅读(189)  评论(0编辑  收藏  举报
Where is the starting point, we don't have a choice, but the destination where we can pursue!