array转xml
function arrayToXml($arr){ $xml = "<xml>"; foreach ($arr as $key=>$val){ if (is_numeric($val)) { $xml.="<".$key.">".$val."</".$key.">"; } else $xml.="<".$key."><![CDATA[".$val."]]></".$key.">"; } $xml.="</xml>"; return $xml; }
效果:
Array ( [appid] => wxd930ea5d5a258f4f [mch_id] => 10000100 [device_info] => 1000 [body] => test [nonce_str] => ibuaiVcKdpRxkhJA [sign] => 9A0A8659F005D6984697E2CA0A9CF3B7 )
转化成:
<xml> <appid> <![CDATA[wxd930ea5d5a258f4f]]> </appid> <mch_id>10000100</mch_id> <device_info>1000</device_info> <body> <![CDATA[test]]> </body> <nonce_str> <![CDATA[ibuaiVcKdpRxkhJA]]> </nonce_str> <sign> <![CDATA[9A0A8659F005D6984697E2CA0A9CF3B7]]> </sign> </xml>