php数组和xml之间相互转化

 //数组转XML
    function arrayToXml($arr)
    {
        $xml = "";
        foreach ($arr as $key=>$val)
        {
            if (is_numeric($val)){
                $xml.="<".$key.">".$val."";
            }else{
                 $xml.="<".$key.">";
            }
        }
        $xml.="";
        return $xml;
    }

    //将XML转为array
    function xmlToArray($xml)
    {    
        //禁止引用外部xml实体
        libxml_disable_entity_loader(true);
        $values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);        
        return $values;
    }
http://www.cnblogs.com/txw1958/p/php-xml-to-array.html

你可能感兴趣的:(php)