Home >Backend Development >PHP Tutorial >This function can parse xml into an array, why?

This function can parse xml into an array, why?

WBOY
WBOYOriginal
2016-08-25 10:37:161090browse

<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>

Reply content:

<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,

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