note 73365 added to ref.dom

From: Date: Tue, 20 Feb 2007 09:09:19 +0000
Subject: note 73365 added to ref.dom
Groups: php.notes 
Request: Send a blank email to php-notes+get-123592@lists.php.net to get a copy of this message
I found the xml2array function below very useful, but there seems to be a bug in it. The $item variable was never getting set. I've expanded this out to be a bit more readable, and the corrected code is : function xmlToArray($n) { $return=array(); foreach($n->childNodes as $nc){ if( $nc->hasChildNodes() ){ if( $n->firstChild->nodeName== $n->lastChild->nodeName&&$n->childNodes->length>1){ $item = $n->firstChild; $return[$nc->nodeName][]=$this->xmlToArray($item); } else{ $return[$nc->nodeName]=$this->xmlToArray($nc); } } else{ $return=$nc->nodeValue; } } return $return; } ---- Server IP: 193.95.141.37 Probable Submitter: 213.94.151.39 ---- Manual Page -- http://www.php.net/manual/en/ref.dom.php Edit -- https://master.php.net/note/edit/73365 Del: integrated -- https://master.php.net/note/delete/73365/integrated Del: useless -- https://master.php.net/note/delete/73365/useless Del: bad code -- https://master.php.net/note/delete/73365/bad+code Del: spam -- https://master.php.net/note/delete/73365/spam Del: non-english -- https://master.php.net/note/delete/73365/non-english Del: in docs -- https://master.php.net/note/delete/73365/in+docs Del: other reasons-- https://master.php.net/note/delete/73365 Reject -- https://master.php.net/note/reject/73365 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123592) next »