xmlToArray 和 arrayToXml 格式转换数组
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 = "<xml>";
foreach ($arr as $key=>$val){
if(is_array($val)){
$xml.="<".$key.">".arrayToXml($val)."</".$key.">";
}else{
$xml.="<".$key.">".$val."</".$key.">";
}
}
$xml.="</xml>";
return $xml ;
}
(xmlToArray method, for reference
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 method, for reference
public function arrayToXml($arr)
{
$xml = "<xml>";
foreach ($arr as $key=>$val){
if(is_array($val)){
$xml.="<".$key.">".arrayToXml($val)."</".$key.">";
}else{
$xml.="<".$key.">".$val."</".$key.">";
}
}
$xml.="</xml>";
return $xml;
})
页:
[1]