//数组转XML function arrayToXml($arr) { $xml = "<xml>"; foreach ($arr as $key=>$val) { if (is_numeric($val)){ $xml.="<".$key.">".$val."</".$key.">"; }else{ $xml.="<".$key.&qu…
如果你使用 curl 获取的 xml data$xml = simplexml_load_string($data);$data['tk'] = json_decode(json_encode($xml),TRUE);如果是直接获取 URL 数据的话$xml = simplexml_load_file($data);$data['tk'] = json_decode(json_encode($xml),TRUE);先把 simplexml 对象转换成 json,再将 json 转换成数组. <?…
原文:分享一个解析XML成为php数组的方法 <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ $xml = 'site_1.xml'; $myxml = simplexml_load_file($xml); // print_r($myxml); print_r(xmlToArray($myxml)); function xmlToArra…
数组转xml格式 $arr=array( 'username'=>'huahua', 'password'=>'123456', 'number'=>'15889652911', ); echo arrayToXml($arr); function arrayToXml($arr){ $xml = "<root>"; foreach ($arr as $key=>$val){ if(is_array($val)){ $xml.="<&…
<?php function xmlToArray2($xml) { // 将XML转为array $array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); return $array_data; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transition…
这里提供一个类来将XML转换为PHP数组,下面是类的代码 <?php/** * XML2Array: A class to convert XML to array in PHP * It returns the array which can be converted back to XML using the Array2XML script * It takes an XML string or a DOMDocument object as an input. * * See Array…
function xmltoarr($path){//xml字符串转数组 $xmlfile = file_get_contents($path);//提取xml文档中的内容以字符串格式赋给变量 $ob= simplexml_load_string($xmlfile,'SimpleXMLElement', LIBXML_NOCDATA);//将字符串转化为变量 $json = json_encode($ob);//将对象转化为JSON格式的字符串 $configData = json_decode…
如果你使用 curl 获取的 xml data $xml = simplexml_load_string($data); $data['tk'] = json_decode(json_encode($xml),TRUE);   如果是直接获取 URL 数据的话 $xml = simplexml_load_file($data); $data['tk'] = json_decode(json_encode($xml),TRUE);   先把 simplexml 对象转换成 json,再将 json…
//将xml字符串转换为数组 public function xmlToArray($xml){ $array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); return $array_data; } /* * 对要发送到微信统一下单接口的数据进行签名 */ public function getSign($Obj,$apiKey){…
<?php $s=join(,file('httpapi.elong.comxmlv2.0hotelcn0132701501.xml')); $result = xml_to_array($s); print_r($result); /*函数*/ function xml_to_array($xml) { $array = (array)(simplexml_load_string($xml)); foreach ($array as $key=$item){ $array[$key] = st…