Php:simplexml - 获取属性值

时间:2013-01-03 12:08:51

标签: php attributes simplexml

<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"/>

嗨,上面是我要阅读的xml文件,我可以获得标题媒体价格甚至 Guid的isPermalink 属性。但是我无法获得媒体:缩略图属性 下面是我的代码。我正在打扰我5个小时:)。

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

请帮助我获取媒体:缩略图属性

1 个答案:

答案 0 :(得分:0)

尝试循环浏览缩略图属性

foreach ($cool->children('media', true)->thumbnail as $thumb) {
   $URL = $thumb['url']
}