note 89702 modified in function.simplexml-element-children by danbrown
| From: | danbrown@php.net | Date: | Thu, 19 Mar 2009 19:54:36 +0000 |
| Subject: | note 89702 modified in function.simplexml-element-children by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152164@lists.php.net to get a copy of this message | ||
Quick easy way to turn objectified SimpleXMLElement data into an array.
<?php
function get_xml_from_some_source(){
//blah blah blah build cUrl
$data = @curl_exec($ch);
$newdata = new SimpleXMLElement($data);
$new = xml2array_parse($newdata);
}
function xml2array_parse($xml){
foreach ($xml->children() as $parent => $child){
$return["$parent"] =
xml2array_parse($child)?xml2array_parse($child):"$child";
}
return $return;
}
?>
My first post, be nice. ;-)
--was--
Quick easy way to turn objectified SimpleXMLElement data into an array.
function get_xml_from_some_source(){
//blah blah blah build cUrl
$data = @curl_exec($ch);
$newdata = new SimpleXMLElement($data);
$new = xml2array_parse($newdata);
}
function xml2array_parse($xml){
foreach ($xml->children() as $parent => $child){
$return["$parent"] =
xml2array_parse($child)?xml2array_parse($child):"$child";
}
return $return;
}
My first post, be nice. ;-)
http://php.net/manual/en/function.simplexml-element-children.php