note 98594 deleted from simplexmlelement.xpath by danbrown
| From: | danbrown@php.net | Date: | Fri, 25 Jun 2010 13:30:09 +0000 |
| Subject: | note 98594 deleted from simplexmlelement.xpath by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170405@lists.php.net to get a copy of this message | ||
Note Submitter: jusvalceanu - SPAM at SPAM - yahoo dot c
----
simple xml 2 array
<?php
/*
* Function getXml2Array();
*
* param: (xml) $xml
*
* return (array)
*/
function getXml2Array($xml) {
$info = array();
foreach ($xml as $key => $value) {
if (is_object($value) and count($value) > 1) {
$info[(string) $key][] = getXml2Array($value);
} else {
$info[(string) $key] = (string) $value;
}
}
return $info;
}
?>
USAGE:
$sx = simplexml_load_string(<XMLSTRING>);
$res = $sx->xpath('//result');
$results = $this->getXml2Array($res);
var_dump($results);
Have fun tweaking this ;)) i know you will ;))
From Romania With Love