单行代码实现xml转换成数组
$string = '<xml> <return_code><![CDATA[SUCCESS]]></return_code> <return_msg><![CDATA[OK]]></return_msg> <appid><![CDATA[wx2421b1c4370ec43b]]></appid> <mch_id><![CDATA[10000100]]></mch_id> <device_info><![CDATA[1000]]></device_info> <nonce_str><![CDATA[sthBJ9QyUG6vkrjJ]]></nonce_str> <sign><![CDATA[6277A96D7875D4FF23AA7B6A4C3046AB]]></sign> <result_code><![CDATA[FAIL]]></result_code> <err_code><![CDATA[PAYERROR]]></err_code> <err_code_des><![CDATA[支付错误]]></err_code_des> </xml>'; $xml =(array)(simplexml_load_string($string,'SimpleXmlElement',LIBXML_NOCDATA)); print_r($xml); //结果如下 C:\wamp\bin\php\php5.4.12\php.exe C:\wamp\www\pra\xml2arr.php Array ( [return_code] => SUCCESS [return_msg] => OK [appid] => wx2421b1c4370ec43b [mch_id] => 10000100 [device_info] => 1000 [nonce_str] => sthBJ9QyUG6vkrjJ [sign] => 6277A96D7875D4FF23AA7B6A4C3046AB [result_code] => FAIL [err_code] => PAYERROR [err_code_des] => 支付错误 ) Process finished with exit code 0