Home >Backend Development >PHP Tutorial >This function can parse xml into an array, why?
<code>function xmlToArray($xml){ // 禁止引用外部xml实体 libxml_disable_entity_loader(true); $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $val = json_decode(json_encode($xmlstring), true); return $val; } </code>
<code>function xmlToArray($xml){ // 禁止引用外部xml实体 libxml_disable_entity_loader(true); $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $val = json_decode(json_encode($xmlstring), true); return $val; } </code>
http://php.net/manual/zh/func...
Yes, the abbreviation is just like this,
function xmlToArray($xml)
{
<code>$array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); return $array_data;</code>
}
WeChat payment comes with it. The interaction between WeChat and the server uses xml format,