note 101010 added to class.domdocument

From: Date: Fri, 19 Nov 2010 20:53:20 +0000
Subject: note 101010 added to class.domdocument
Groups: php.notes 
Request: Send a blank email to php-notes+get-174212@lists.php.net to get a copy of this message
A nice and simple node 2 array I wrote, worth a try ;) $dom = new DOMDocument(); $dom->loadXML("test.xml"); echo "<PRE>"; print_r(getArray($dom->documentElement)); function getArray($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] = $this->getArray($node->firstChild); } else { foreach ($node->childNodes as $childNode) { if ($childNode->nodeType != XML_TEXT_NODE) { $array[$childNode->nodeName][] = $this->getArray($childNode); } } } } else { return $node->nodeValue; } return $array; } ---- Server IP: 83.137.20.135 Probable Submitter: 217.121.212.191 ---- Manual Page -- http://www.php.net/manual/en/class.domdocument.php Edit -- https://master.php.net/note/edit/101010 Del: integrated -- https://master.php.net/note/delete/101010/integrated Del: useless -- https://master.php.net/note/delete/101010/useless Del: bad code -- https://master.php.net/note/delete/101010/bad+code Del: spam -- https://master.php.net/note/delete/101010/spam Del: non-english -- https://master.php.net/note/delete/101010/non-english Del: in docs -- https://master.php.net/note/delete/101010/in+docs Del: other reasons-- https://master.php.net/note/delete/101010 Reject -- https://master.php.net/note/reject/101010 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174212) next »