note 96842 deleted from book.dom by thiago

From: Date: Thu, 18 Mar 2010 23:35:06 +0000
Subject: note 96842 deleted from book.dom by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-167187@lists.php.net to get a copy of this message
Note Submitter: LWC ---- Here's no-#text support for the last function: function dom_to_array($root, $showtextdata=false) { $result = array(); if ($root->hasAttributes()) { $attrs = $root->attributes; foreach ($attrs as $i => $attr) $result[$attr->name] = $attr->value; } $children = $root->childNodes; if ($children->length == 1) { $child = $children->item(0); if ($child->nodeType == XML_TEXT_NODE) { $result['_value'] = $child->nodeValue; if (count($result) == 1) return $result['_value']; else return $result; } } $group = array(); for($i = 0; $i < $children->length; $i++) { $child = $children->item($i); if ($showtextdata || $child->nodeName <> '#text') { if (!isset($result[$child->nodeName])) $result[$child->nodeName] = dom_to_array($child); else { if (!isset($group[$child->nodeName])) { $tmp = $result[$child->nodeName]; $result[$child->nodeName] = array($tmp); $group[$child->nodeName] = 1; } $result[$child->nodeName][] = dom_to_array($child); } } } return $result; }

« previous php.notes (#167187) next »