1
//数组转XML
2 function arrayToXml($arr)
3 {
4 $xml = "<xml>";
5 foreach ($arr as $key=>$val)
6 {
7 if (is_numeric($val)){
8 $xml.="<".$key.">".$val."</".$key.">";
9 }else{
10 $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
11 }
12 }
13 $xml.="</xml>";
14 return $xml;
15 }
16
17 //将XML转为array
18 function xmlToArray($xml)
19 {
20 //禁止引用外部xml实体
21 libxml_disable_entity_loader(true);
22 $values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
23 return $values;
24 }
header("Content-type:text/html;charset=utf-8");