xml转数组
<?php $str1 = '<xml><appid><![CDATA[wxba5a33c7647a0002]]></appid> <attach><![CDATA[12123]]></attach> <bank_type><![CDATA[CFT]]></bank_type> <cash_fee><![CDATA[1]]></cash_fee> <fee_type><![CDATA[CNY]]></fee_type> <is_subscribe><![CDATA[N]]></is_subscribe> <mch_id><![CDATA[1491300832]]></mch_id> <nonce_str><![CDATA[sbojth6jkjifmesfrd8ov3nzcex090hv]]></nonce_str> <openid><![CDATA[orOH00CLjYPLVQ5oj6UbmGlHAAAA]]></openid> <out_trade_no><![CDATA[149130083220171117105752]]></out_trade_no> <result_code><![CDATA[SUCCESS]]></result_code> <return_code><![CDATA[SUCCESS]]></return_code> <sign><![CDATA[58A616502EA22FEB5B3981BCA5246F21]]></sign> <time_end><![CDATA[20171117105757]]></time_end> <total_fee>1</total_fee> <trade_type><![CDATA[JSAPI]]></trade_type> <transaction_id><![CDATA[4200000015201711175187860938]]></transaction_id> </xml>'; //处理xml字符串 $str = str_replace('<xml>', '', $str1); //把xml转化成多个<a>...</a>格式的数组 preg_match_all('/\<\w+\>.+\<\/\w+\>/', $str, $arr); $axml = []; //遍历处理得到的数组 foreach ($arr[0] as $value) { //遍历解析得到的数组 //得到一个假key preg_match_all('/\<\w+\>/', $value, $ks); //处理假key $k = substr($ks[0][0],1,-1); //得到一个假value preg_match_all('/\>\<.+\>\</', $value, $vs); //处理假value if (empty($vs[0][0])) { preg_match_all('/\>\w+\</', $value, $v1); $v = substr($v1[0][0],1,-1); }else{ $v = substr($vs[0][0],10,strlen($vs[0][0])-14); } $axml[$k] = $v; } var_dump($axml);