php xml转数组 自定义xml_to_array

时间:2022-07-09 05:33:21
 <?php
header("Content-type: text/xml; charset=utf-8");
$con = file_get_contents('xml路径');
//XML标签配置
$xmlTag = array(
'execProc_stringResult'
);
$arr = array();
foreach ($xmlTag as $x) {
preg_match_all("/<" . $x . ">.*<\/" . $x . ">/", $con, $temp);
$arr[] = $temp[0];
}
//去除XML标签并组装数据
$data = array();
foreach ($arr as $key => $value) {
foreach ($value as $k => $v) {
$a = explode($xmlTag[$key] . '>', $v);
$v = substr($a[1], 0, strlen($a[1]) - 2);
$data[$k][$xmlTag[$key]] = $v;
}
}
$jsonstr = $data[0]['execProc_stringResult'];
$arr = json_decode($jsonstr, true);
var_dump($arr);

php xml转数组 自定义xml_to_array

欢迎沟通交流