标签:
function xml2array($xmlString = ‘‘) { $targetArray = array(); $xmlObject = simplexml_load_string($xmlString); $mixArray = (array)$xmlObject; foreach($mixArray as $key => $value) { if(is_string($value)){ $targetArray[$key] = $value; } if(is_object($value)){ $targetArray[$key] = xml2array($value->asXML()); } if(is_array($value) && $key != ‘@attributes‘){ foreach($value as $zkey => $zvalue){ if(is_numeric($zkey)){ $targetArray[$key][] = xml2array($zvalue->asXML()); } if(is_string($zkey)){ $targetArray[$key][$zkey] = xml2array($zvalue->asXML()); } } } //获取元素属性 if(is_array($value) && $key == ‘@attributes‘) { foreach($value as $zkey => $zvalue) { if(is_numeric($zkey)) { $targetArray[$key][] = $zvalue; } elseif(is_string($zkey)) { $targetArray[$key][$zkey] = $zvalue; } } } } return $targetArray; }
标签:
原文地址:http://www.cnblogs.com/wumingcong/p/4664105.html