note 68374 added to ref.simplexml
| From: | charles at etherscapes dot com | Date: | Tue, 25 Jul 2006 01:32:38 +0000 |
| Subject: | note 68374 added to ref.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115111@lists.php.net to get a copy of this message | ||
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;
}
----
Server IP: 64.71.164.2
Probable Submitter: 206.126.9.90
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/ref.simplexml.php
Edit -- http://master.php.net/note/edit/68374
Del: integrated -- http://master.php.net/note/delete/68374/integrated
Del: useless -- http://master.php.net/note/delete/68374/useless
Del: bad code -- http://master.php.net/note/delete/68374/bad+code
Del: spam -- http://master.php.net/note/delete/68374/spam
Del: non-english -- http://master.php.net/note/delete/68374/non-english
Del: in docs -- http://master.php.net/note/delete/68374/in+docs
Del: other reasons-- http://master.php.net/note/delete/68374
Reject -- http://master.php.net/note/reject/68374
Search -- http://master.php.net/manage/user-notes.php