Php 为什么访问simpleXML对象时输出为空?
我的simpleXMLElement输出Php 为什么访问simpleXML对象时输出为空?,php,xml,Php,Xml,我的simpleXMLElement输出 SimpleXMLElement Object ( [guid] => 2898580 [title] => England's doomed inevitability? [description] => [link] => http://www.espnfc.com/blog/the-match/60/post/2895340/roy-hodgson-rings-the-changes-but-england-strugg
SimpleXMLElement Object
(
[guid] => 2898580
[title] => England's doomed inevitability?
[description] =>
[link] => http://www.espnfc.com/blog/the-match/60/post/2895340/roy-hodgson-rings-the-changes-but-england-struggle-again
[pubDate] => Jun 20, 2016 04:58 PM PDT
[enclosure] => SimpleXMLElement Object
(
[@attributes] => Array
(
[length] => 150
[url] => http://a.espncdn.com/combiner/i/?img=/photo/2016/0620/r94714_1296x729_16-9.jpg&w=100&h=80&scale=crop&site=espnfc
[type] => image/jpeg
)
)
[category] => null
)
PHP
在foreach循环的帮助下打印
echo "Img_Url:".$img_url = $item->enclosure->attributes['url'] ;
它将显示空白,但我写了这个
echo "Img_Url:".$img_url = $item->enclosure->@attributes['url'] ;
它给出了语法错误
那么如何打印它。要访问属性,只需将SimpleXMLElement对象视为数组。不要在对象的内部结构中四处挖掘
echo "Img_Url: " . (string) $item->enclosure['url'];
请参见要访问属性,只需将SimpleXMLElement对象视为数组。不要在对象的内部结构中四处挖掘
echo "Img_Url: " . (string) $item->enclosure['url'];
请参见在我看来,您需要将@符号用如下内容包围:
echo“Img_Url:”.$Img_Url=$item->enclosure->{@attributes}['Url']代码>符号@用于抑制PHP中的错误消息。SimpleXMLElement-objects始终返回其他对象。尝试将其转换为字符串:echo“Img\u Url:”。$Img\u Url=(字符串)$item->enclosure->attributes['Url']
@Henders无法正常工作blank@MagnusEriksson不工作检查此项:在我看来,您需要用类似以下内容围绕@符号:echo“Img_Url:”.$Img_Url=$item->enclosure->{@attributes}['Url']代码>符号@用于抑制PHP中的错误消息。SimpleXMLElement-objects始终返回其他对象。尝试将其转换为字符串:echo“Img\u Url:”。$Img\u Url=(字符串)$item->enclosure->attributes['Url']
@Henders无法正常工作blank@MagnusEriksson不工作检查:谢谢,很容易,很容易