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; }
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>
converted into:
Array ( [appid] => wxd930ea5d5a258f4f [mch_id] => 10000100 [device_info] => 1000 [body] => test [nonce_str] => ibuaiVcKdpRxkhJA [sign] => 9A0A8659F005D6984697E2CA0A9CF3B7 )
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!