simplexml to array and array to xml
发布时间:2020-12-16 05:20:46 所属栏目:百科 来源:网络整理
导读:function sxml2arr($xml){$arr = (array)$xml;foreach ($arr as $key = $value) {if($value instanceof simplexmlElement || is_array($value)){$arr[$key] = sxml2arr($value);}}return $arr;} function arr2xml($arr,$node=NULL){if($node === NULL){$xml
function sxml2arr($xml) { $arr = (array)$xml; foreach ($arr as $key => $value) { if($value instanceof simplexmlElement || is_array($value)) { $arr[$key] = sxml2arr($value); } } return $arr; }
function arr2xml($arr,$node=NULL) { if($node === NULL) { $xml = new simplexmlElement("<?xml version='1.0' encoding='utf-8'?><geng></geng>"); } else { $xml = $node; } foreach ($arr as $key => $value) { if(is_array($value)) { if(is_numeric($key)) { arr2xml($value,$xml->addChild('item'.$key)); } else { arr2xml($value,$xml->addChild($key)); } } else if(is_numeric($key)) { $xml->addChild('item'.$key,$value); }else { $xml->addChild($key,$value); } } return $xml; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |