Skip to content
Advertisement

Php : simplexml – Getting attribute value

<guid isPermaLink="false">

<title>iphone cover 4</title>

<media:price>$35.95</media:price>

<media:thumbnail url="http://rlv.zcache.com/22.jpg"/>

<media:content url="http://rlv.zcache.com/440.jpg"/>

Above is the xml file I want to read, I can get title, media price and even Guid’s isPermalink attribute. But I cannot get media:thumbnail attribute Below is my code.

foreach ($xml->channel->item as $cool)
{
    $per = $cool->guid["isPermaLink"];
    $thumb = $cool->children('media', true)->price;
    $title = $cool->title;
    $thumb = $cool->children('media', true)->thumbnail["url"];
}

How do I get media:thumbnail attribute?

Advertisement

Answer

Try to cycle through thumbnail attributes

foreach ($cool->children('media', true)->thumbnail as $thumb) {
   $URL = $thumb['url']
}
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement