note 93426 deleted from function.simplexml-element-children by danbrown

From: Date: Wed, 16 Sep 2009 15:32:10 +0000
Subject: note 93426 deleted from function.simplexml-element-children by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-160686@lists.php.net to get a copy of this message
Note Submitter: martin at classaxe in the land of com ---- Simplied function based on one by rodmen at gmail dot com (with less nested output) <?php $Obj_SimpleXML = SimpleXML_Load_String($xml_doc); function xml2phpArray($Obj_SimpleXML){ $siblings = array(); $children = $Obj_SimpleXML->children(); foreach($children as $child){ $key = $child->getName(); if($child->children()){ $siblings[$key] = xml2phpArray($child); } else { $siblings[$key] = trim($child[0]); } } return $siblings; } $output = xml2phpArray($Obj_SimpleXML) print_r($output); ?>

« previous php.notes (#160686) next »