时间:2021-07-01 10:21:17 帮助过:7人阅读
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]);