时间:2021-07-01 10:21:17 帮助过:4人阅读
在线等,希望能有人速度帮忙解决了
找一个xml_to_array的函数 比如
http://www.cnblogs.com/heiing/archive/2009/12/31/1637015.html
然后使用它
function xml_to_array( $xml ){ $reg = "/<(\\w+)[^>]*?>([\\x00-\\xFF]*?)<\\/\\1>/"; if(preg_match_all($reg, $xml, $matches)) { $count = count($matches[0]); $arr = array(); for($i = 0; $i < $count; $i++) { $key = $matches[1][$i]; $val = xml_to_array( $matches[2][$i] ); // 递归 if(array_key_exists($key, $arr)) { if(is_array($arr[$key])) { if(!array_key_exists(0,$arr[$key])) { $arr[$key] = array($arr[$key]); } }else{ $arr[$key] = array($arr[$key]); } $arr[$key][] = $val; }else{ $arr[$key] = $val; } } return $arr; }else{ return $xml; }}// Xml 转 数组, 不包括根键function xmltoarray( $xml ){ $arr = xml_to_array($xml); $key = array_keys($arr); return $arr[$key[0]];}$xml = '0000ax000011122233344212345测试402100002885328320130828 ';var_export(xmltoarray($xml));备注1 备注2 备注3
array ( 'ax' => '0000', 'at' => 'ax0000111222333442', 'ab' => '12345', 'an' => '测试', 'ao' => '4021000028853283', 'ad' => '20130828', 'pMemo1' => '备注1', 'pMemo2' => '备注2', 'pMemo3' => '备注3',)
谢谢了,解决!