1 <?php 2 header("Content-type: text/xml; charset=utf-8"); 3 $con = file_get_contents('xml路径'); 4 //XML标签配置 5 $xmlTag = array( 6 'execProc_stringResult' 7 ); 8 $arr = array(); 9 foreach ($xmlTag as $x) { 10 preg_match_all("/<" . $x . ">.*</" . $x . ">/", $con, $temp); 11 $arr[] = $temp[0]; 12 } 13 //去除XML标签并组装数据 14 $data = array(); 15 foreach ($arr as $key => $value) { 16 foreach ($value as $k => $v) { 17 $a = explode($xmlTag[$key] . '>', $v); 18 $v = substr($a[1], 0, strlen($a[1]) - 2); 19 $data[$k][$xmlTag[$key]] = $v; 20 } 21 } 22 $jsonstr = $data[0]['execProc_stringResult']; 23 $arr = json_decode($jsonstr, true); 24 var_dump($arr);
php xml转数组 自定义xml_to_array
欢迎沟通交流