为什么这是错的?
[enclosure] => SimpleXMLElement Object
(
[@attributes] => Array
(
[url] => http://www.thestar.com.my/~/media/Images/TSOL/Photos-Gallery/features/2014/07/02/dominiclau020714.ashx?crop=1&w=460&h=345&
[length] =>
[type] => image/jpeg
)
)
我想获取获取图像文件的网址
我写了print_r($eachItem->enclosure['@attributes']->url)
它不起作用。为什么呢?
答案 0 :(得分:1)
这不是获取属性值的正确方法。使用->attributes()
方法:
echo (string) $eachItem->enclosure->attributes()['url'];
// as of PHP 5.4 (dereferencing)
或者
// PHP 5.3 below
$eachItem_attribute = $eachItem->enclosure->attributes();
echo (string) $eachItem_attribute['url'];
答案 1 :(得分:0)
$eachItem->enclosure->attributes()->{'url'};