Instance analysis of PHP custom function xmlToArray

coldplay.xixi
Release: 2023-04-08 19:20:01
forward
2422 people have browsed it

Instance analysis of PHP custom function xmlToArray

PHP custom function xmlToArray instance

Convert xml to array

/**
 *  作用:将xml转为array
 */
function xmlToArray($xml) {
    //将XML转为array
    $array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
    return $array_data;
}
Copy after login

Effect:

<xml>
<appid>wxd930ea5d5a258f4f</appid>
<mch_id>10000100</mch_id>
<device_info>1000</device_info>
<body>test</body>
<nonce_str>ibuaiVcKdpRxkhJA</nonce_str>
<sign>9A0A8659F005D6984697E2CA0A9CF3B7</sign>
</xml>
Copy after login

converted into:

Array
(
    [appid] => wxd930ea5d5a258f4f
    [mch_id] => 10000100
    [device_info] => 1000
    [body] => test
    [nonce_str] => ibuaiVcKdpRxkhJA
    [sign] => 9A0A8659F005D6984697E2CA0A9CF3B7
)
Copy after login

Recommended tutorial: "PHP Video Tutorial"

The above is the detailed content of Instance analysis of PHP custom function xmlToArray. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:liqingbo.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