note 61254 added to ref.domxml

From: Date: Sun, 29 Jan 2006 16:13:07 +0000
Subject: note 61254 added to ref.domxml
Groups: php.notes 
Request: Send a blank email to php-notes+get-102671@lists.php.net to get a copy of this message
### Moderator: ### This is a very slight tweak to to the dom_to_simple_array function posted earliers by jas at uci dot edu. I recommend just editing the previous post rather than posting the function again. --------------------------------- The previously posted dom_to_simple_array function has a slight error, which prevents PHP from processing if there are attributes present. The line that reads: $attributes = $domnode->attributes(); ... should read: $attributes = $domnode->attributes; --------------------------------- Here is the full code again with the correction: function dom_to_simple_array($domnode, &$array) { $array_ptr = &$array; $domnode = $domnode->firstChild; while (!is_null($domnode)) { if (! (trim($domnode->nodeValue) == "") ) { switch ($domnode->nodeType) { case XML_TEXT_NODE: { $array_ptr['cdata'] = $domnode->nodeValue; break; } case XML_ELEMENT_NODE: { $array_ptr = &$array[$domnode->nodeName][]; if ($domnode->hasAttributes() ) { $attributes = $domnode->attributes; if (!is_array ($attributes)) { break; } foreach ($attributes as $index => $domobj) { $array_ptr[$index] = $array_ptr[$domobj->name] = $domobj->value; } } break; } } if ( $domnode->hasChildNodes() ) { dom_to_simple_array($domnode, $array_ptr); } } $domnode = $domnode->nextSibling; } } ---- Server IP: 216.194.113.175 Probable Submitter: 68.8.68.231 ---- Manual Page -- http://www.php.net/manual/en/ref.domxml.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61254 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61254&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61254&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61254&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61254&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61254&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61254&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61254&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61254&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102671) next »