[resolved] SimpleXML difficulties, please help
Posted: Sun Jul 12, 2009 5:39 pm
I am having great difficulties trying to access and loop through the following SimpleXML object. The object is a simplified response from the Flickr API. Following the Object is the foreach loop I am trying to use to parse the needed data into a more convenient associative array with the "label" attribute as the key. I've tried everything I can think of and have had no luck thus far. Any help is appreciated, thanks!
my foreach
Code: Select all
SimpleXMLElement Object
(
[@attributes] => Array
(
[stat] => ok
)
[sizes] => SimpleXMLElement Object
(
[@attributes] => Array
(
[canblog] => 0
[canprint] => 0
[candownload] => 1
)
[size] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[label] => Square
[width] => 75
[height] => 75
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[label] => Thumbnail
[width] => 100
[height] => 75
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[label] => Small
[width] => 240
[height] => 180
)
)
)
)
)
Code: Select all
foreach ($sizes->size as $size)
{
$label = strtolower((string) $size["label"]);
$info["sizes"][$label] = array(
"width" => (string) $size["width"],
"height" => (string) $size["height"]
);
}