2

I am Parsing XML currently using:

$data = simplexml_load_string($xmlFile);
foreach($data->item as $key => $current){
   echo($current);
}

However I'm wondering, if a hit an element that looks like this:

<thumbnail url="http://foo.bar" height="225" width="300"/>

How do i pull the inner parts of this? (height, url, width)

Thanks!

2 Answers 2

10
foreach($data->item->thumbnail as $thumbnail) {

    $url = $thumbnail['url'];
    $height = $thumbnail['height'];
    $width = $thumbnail['width'];
}
Sign up to request clarification or add additional context in comments.

1 Comment

Cheers. Didn't know I could navigate through the attribute like that.
3

In case you don't know how many attributes there will be...

foreach ($data->item->thumbnail->attributes() as $key => $value) {
    $attr[$key] = (string)$value;
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.