note 58683 deleted from ref.domxml by sobak

From: Date: Fri, 25 Nov 2016 05:39:18 +0000
Subject: note 58683 deleted from ref.domxml by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207641@lists.php.net to get a copy of this message
Note Submitter: websiterepairguys at spamnot dot yahoo dot com ---- I tried using the dom_to_simple_array that the user jas posted above, but it didnt work very well. The problems were it didnt handle sibling nodes with the same name, such as: <nodes> <node>something</node> <node>something</node> </nodes> Also, when it built child arrays from child nodes, it always interjected an wrapping array around the child, which isnt necessary. Here is the patched code: function dom_to_array($domnode, &$array) { $parent=$domnode; $domnode = $domnode->firstChild; $myname=$domnode->nodeName; $x=1; while (!is_null($domnode)) { switch ($domnode->nodeType) { case XML_ELEMENT_NODE: { if ( !$domnode->hasChildNodes()) { $array[$domnode->nodeName]=''; } else if ( $domnode->hasChildNodes() && $domnode->firstChild->nodeType==XML_TEXT_NODE) { $array[$domnode->nodeName]=$domnode->firstChild->nodeValue; } else if ( $domnode->hasChildNodes() ) { $array_ptr = & $array[$domnode->nodeName]; dom_to_array($domnode, $array_ptr); break; } } } $domnode = $domnode->nextSibling; if($domnode->nodeName==$myname) { $domnode->nodeName.=($x++); } } } snippet of array produced by this: [admin] => Array ( [menu] => Array ( [title] => Page Manager [view] => list ) [files] => Array ( [filename] => modules/testmodule/testmodule.php [filename1] => modules/testmodule/testmodule.xml [filename2] => media/lang/en-us/templates/testmodule.tpl ) )

« previous php.notes (#207641) next »