functionArraytoxml ($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; } //Convert XML to array functionXmltoarray ($xml) { //Disallow referencing of external XML entitiesLibxml_disable_entity_loader (true); $values= Json_decode (Json_encode (simplexml_load_string($xml, ' SimpleXMLElement ', libxml_nocdata),true); return $values; }
$obj 2= "<xml> <wxappid><![ cdata[wx1b7559b818e3c123]]></wxappid> <mch_id>1235571234</mch_id> <mch_billno >1235571234201605241726128109</mch_billno> <client_ip><![ Cdata[127.0.0.1]]></client_ip> <re_openid><![ Cdata[oipudugv7gj_mosfawpvmhhgxh-u]]></re_openid> <total_amount>101</total_amount> <min_value>101</min_value> <max_value>101</max_value> <total_num> 1</total_num> <nick_name><![ cdata[Studio]]></nick_name> <send_name><![ cdata[Studio]]></send_name> <wishing><![ cdata[Congratulations]]></wishing> <act_name><![ cdata[Double Studio Send red envelopes]]></act_name> <remark><![ cdata[attention to public account]]></remark></xml>";
Print results
Array([Wxappid]=wx1b7559b818e3c123 [mch_id]= 1235571234[Mch_billno]= 1235571234201605241726128109[CLIENT_IP]= 127.0.0.1[Re_openid]= oipudugv7gj_mosfawpvmhhgxh-U [Total_amount]= 101[Min_value]= 101[Max_value]= 101[Total_num]= 1[Nick_name]=Fang Times Studio [Send_name]=Fang Times Studio [wishing]=congratulations on getting rich [act_name]=Fang Times Studio send red envelopes [remark]=follow the public account)
PHP XML and array conversion functions