This function can parse xml into an array, why?

WBOY
Release: 2016-08-25 10:37:16
Original
1012 people have browsed it

<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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

}
WeChat payment comes with it. The interaction between WeChat and the server uses xml format,

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!