/**
* node2array函数,将xml转换为数组
* @param object $node
*/
public function node2array($node){
$array = false;
if ($node->hasAttributes()){
foreach ($node->attributes as $attr){
$array[$attr->nodeName] = $attr->nodeValue;
}
}
if ($node->hasChildNodes()){
if ($node->childNodes->length == 1){
$array[$node->firstChild->nodeName] = $node->firstChild->nodeValue;
}else{
foreach ($node->childNodes as $childNode){
if ($childNode->nodeType != XML_TEXT_NODE){
if($childNode->childNodes->length == 1){
$array[$childNode->nodeName] = $childNode->firstChild->nodeValue;
}else{
$array[$childNode->nodeName][] = $this->node2array($childNode);
}
}
}
}
}
return $array;
}
时间: 2024-11-05 06:12:42