代码
<?php //数组转换 XML function toXml($values) { if (!is_array($values) || count($values) <= 0) { return false; } $xml = "<xml>"; foreach ($values as $key => $val) { if (is_numeric($val)) { $xml .= "<" . $key . ">" . $val . "</" . $key . ">"; } else { $xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">"; } } $xml .= "</xml>"; return $xml; }
<?php //XML 转成数组 function fromXml($xml) { // 禁止引用外部 xml 实体 libxml_disable_entity_loader(true); return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); }
吐槽
记录一下.以后会用到.
丫的.说好放假 3 天.就放了两天.真恶心.