Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Xml Attribute Parsing

Tags:

php

parsing

xml

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!

like image 506
Petrogad Avatar asked Feb 13 '26 16:02

Petrogad


1 Answers

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

    $url = $thumbnail['url'];
    $height = $thumbnail['height'];
    $width = $thumbnail['width'];
}
like image 169
rojoca Avatar answered Feb 15 '26 05:02

rojoca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!