note 68374 deleted from ref.simplexml by didou

From: Date: Tue, 16 Jan 2007 00:55:43 +0000
Subject: note 68374 deleted from ref.simplexml by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-121774@lists.php.net to get a copy of this message
Note Submitter: charles at etherscapes dot com ---- This function replaces the one I just posted. It was skipping the first child item. 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 (#121774) next »