xmlToArray方法
public function xmlToArray($xml)
{
libxml_disable_entity_loader(true);
$xmlstring = simplexml_load_string($xml,'SimpleXMLElement',LIBXML_NOCDATA);
$val = json_decode(json_encode($xmlstring),true);
// libxml_disable_entity_loader(true);
// $result = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $val;
}
arrayToXml方法
public function arrayToXml($arr)
{
$xml = "";
foreach ($arr as $key=>$val){
if(is_array($val)){
$xml.="<".$key.">".arrayToXml($val)."".$key.">";
}else{
$xml.="<".$key.">".$val."".$key.">";
}
}
$xml.="";
return $xml ;
}