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 = "";
    foreach ($arr as $key=>$val){
        if(is_array($val)){
            $xml.="<".$key.">".arrayToXml($val)."";
        }else{
            $xml.="<".$key.">".$val."";
        }
    }
    $xml.="";
    return $xml ;
}
联系我们

邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453

Copyright © 2015-2024

备案号:京ICP备15003423号-3