[resolved] SimpleXML difficulties, please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fenix
Forum Newbie
Posts: 1
Joined: Sun Jul 12, 2009 5:26 pm

[resolved] SimpleXML difficulties, please help

Post by fenix »

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!

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
                                )
                        )
                )
        )
)
 
my foreach

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"]
        );
}
 
Post Reply