note 40361 deleted from ref.simplexml by aidan

From: Date: Mon, 28 Jun 2004 00:36:48 +0000
Subject: note 40361 deleted from ref.simplexml by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71975@lists.php.net to get a copy of this message
Note Submitter: ash@bigfoot.de ---- I had problems to use SimpleXML with OpenOffice's content.xml. Although print_r($simple_xml); printed the whole XML object simplexml_element Object ( [script] => simplexml_element Object ( ) [font-decls] => simplexml_element Object ( [font-decl] => Array ... all first level object vars (script, font-decls, automatic-styles, body) contained nothing if I tried to access them: print_r($simple_xml->{'font-decls'}); returned simplexml_element Object ( ) and direct access to a deeper value returns NULL: echo(gettype($simple_xml->{'font-decls'}->{'font-decl'})); So I wrote a function to turn the whole object into an array, maybe you find it useful. function &simpleXMLtoArray(&$simple_xml) { $xml_array = (array)$simple_xml; $result = array(); foreach ($xml_array as $key => $value) { if(is_object($value) || is_array($value)) $result[$key]=&simpleXMLtoArray($value); else $result[$key]=$value; } return $result; } print_r(simpleXMLtoArray($simple_xml));

« previous php.notes (#71975) next »