]* >([\x00-\xFF]*)<\/\1>/"; if(preg_match_all($reg, $xml, $matches)) { $count = count($matches[0]); for("/> ]* >([\x00-\xFF]*)<\/\1>/"; if(preg_match_all($reg, $xml, $matches)) { $count = count($matches[0]); for(">
Home > Article > Backend Development > Convert XML to array under xtreme toolkit pro php
Copy the 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))
{
$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]];
}
The above introduces the conversion of XML into an array under xtreme toolkit pro php, including the content of xtreme toolkit pro. I hope it will be helpful to friends who are interested in PHP tutorials.