Copy CodeThe code is as follows:
XML-to-array, including the root key
function Xml_to_array ($xml)
{
$reg = "/< (\w+) [^>]*> ([\\x00-\\xff]*) <\\/\\1>/";
if (Preg_match_all ($reg, $xml, $matches))
{
$count = count ($matches [0]);
for ($i = 0; $i < $count; $i + +)
{
$subxml = $matches [2][$i];
$key = $matches [1][$i];
if (Preg_match ($reg, $subxml))
{
$arr [$key] = Xml_to_array ($subxml);
}else{
$arr [$key] = $subxml;
}
}
}
return $arr;
}
Xml to array, not including root key
function Xmltoarray ($xml)
{
$arr = Xml_to_array ($xml);
$key = Array_keys ($arr);
return $arr [$key [0]];
}
http://www.bkjia.com/PHPjc/321043.html www.bkjia.com true http://www.bkjia.com/PHPjc/321043.html techarticle The copy code code is as follows://XML to the array, including the root key function Xml_to_array ($xml) {$reg = "/(\w+) [^]* ([\\x00-\\xff]*) \\/\\1/"; if (Preg_match _all ($reg, $xml, $matches)) {$c ...