note 75553 added to ref.dom

From: Date: Tue, 05 Jun 2007 09:45:57 +0000
Subject: note 75553 added to ref.dom
Groups: php.notes 
Request: Send a blank email to php-notes+get-127221@lists.php.net to get a copy of this message
appended to brian dot reynolds at risaris dot com 20-Feb-2007 10:09 when you got variable nodes at start you array fails and looses nodes beneath. solution that counts occurance though eats up performance: function xmlToArray($n) { $xml_array = array(); $occurance = array(); foreach($n->childNodes as $nc) { $occurance[$nc->nodeName]++; } foreach($n->childNodes as $nc){ if( $nc->hasChildNodes() ) { if($occurance[$nc->nodeName] > 1) { $xml_array[$nc->nodeName][] = xmlToArray($nc); } else { $xml_array[$nc->nodeName] = xmlToArray($nc); } } else { return utf8_decode($nc->nodeValue); } } return $xml_array; } ---- Server IP: 192.35.244.50 Probable Submitter: 86.59.20.26 ---- Manual Page -- http://www.php.net/manual/en/ref.dom.php Edit -- https://master.php.net/note/edit/75553 Del: integrated -- https://master.php.net/note/delete/75553/integrated Del: useless -- https://master.php.net/note/delete/75553/useless Del: bad code -- https://master.php.net/note/delete/75553/bad+code Del: spam -- https://master.php.net/note/delete/75553/spam Del: non-english -- https://master.php.net/note/delete/75553/non-english Del: in docs -- https://master.php.net/note/delete/75553/in+docs Del: other reasons-- https://master.php.net/note/delete/75553 Reject -- https://master.php.net/note/reject/75553 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127221) next »