Copy code The code is as follows:
// Convert Xml to array, including 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, excluding root key
function xmltoarray( $xml )
{
$arr = xml_to_array($xml);
$key = array_keys($arr);
return $arr[$key[0]];
}
http://www.bkjia.com/PHPjc/321043.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321043.htmlTechArticleCopy code The code is as follows: // Xml to array, including root key function xml_to_array( $xml ) { $reg = "/(w+)[^]*([\x00-\xFF]*)\/\1/"; if(preg_match_all($reg, $xml, $matches)) { $c...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn