数组转xml /* * * 数组转xml */ public function arrayToXml( $arr ){ $xml = "xml" ; foreach ( $arr as $key = $val ) { if ( is_numeric ( $val )){ $xml .="". $key ."". $val ."/". $key ."" ; } else { $xml .="". $key ."![CDATA[". $val ."]]/"
数组转xml
/** * 数组转xml */ public function arrayToXml($arr){ $xml = "<xml>"; foreach ($arr as $key=>$val) { if (is_numeric($val)){ $xml.="<".$key.">".$val."</".$key.">"; }else{ $xml.="<".$key."><![CDATA[".$val."]]></".$key.">"; } } $xml.="</xml>"; return $xml; }
xml转数组
/** * xml转数组 */ public function xmlToArray($xml){ //禁止引用外部xml实体 libxml_disable_entity_loader(true); $values = json_decode(json_encode(simplexml_load_string($xml, ‘SimpleXMLElement‘, LIBXML_NOCDATA)), true); return $values; }