note 68286 deleted from ref.simplexml by danbrown

From: Date: Mon, 18 May 2009 01:24:52 +0000
Subject: note 68286 deleted from ref.simplexml by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155530@lists.php.net to get a copy of this message
Note Submitter: charles at etherscapes dot com ---- Just a minor modification to Daniel Favire's simplexml2ISOarray function: I added an if-block around the attributes section so you don't get a SimpleXML attributes element along with each attributes array: function simplexml2ISOarray($xml,$attribsAsElements=0) { if (get_class($xml) == 'SimpleXMLElement') { $attributes = $xml->attributes(); foreach($attributes as $k=>$v) { if ($v) $a[$k] = (string) $v; } $x = $xml; $xml = get_object_vars($xml); } if (is_array($xml)) { if (count($xml) == 0) return (string) $x; // for CDATA foreach($xml as $key=>$value) { $r[$key] = simplexml2ISOarray($value,$attribsAsElements); if (!is_array($r[$key])) $r[$key] = utf8_decode($r[$key]); } if (isset($a)) { if($attribsAsElements) { $r = array_merge($a,$r); } else { $r['@'] = $a; // Attributes } } return $r; } return (string) $xml; }

« previous php.notes (#155530) next »