【发布时间】:2015-05-05 22:31:00
【问题描述】:
0这是我的 rss 提要的相关部分:
<channel>
<description></description>
<title>Untitled</title>
<generator>Tumblr (3.0; @xxx)</generator>
<link>http://xxx.tumblr.com/</link>
<item>
<title>Title</title>
<description><figure><img src="https://31.media.tumblr.com/c78c7t3abd23423549d3bb0f705/tumblr_inline_nkp9z234d0uj.jpg"/></figure></description>
<link>http://xxx.tumblr.com/post/99569244093</link>
<guid>http://xxx.tumblr.com/post/99569244093</guid>
<pubDate>Thu, 09 Oct 2014 11:19:33 -0400</pubDate>
</item>
</channel>
使用此处其他问题的答案,我尝试了这个:
$content = file_get_contents("http://xxx.tumblr.com/rss");
$feed = new SimpleXmlElement($content);
$imgs = $feed->channel->item[0]->description->xpath('//img');
foreach($imgs as $image) {
echo (string)$image['src'];
};
这将为$imgs返回一个空数组
这与&lt; &gt;等标签有关吗?
如果可以,我该怎么办?
【问题讨论】:
-
您发布的 XML 中没有
img元素。&lt;img src="..."/&gt;不算数。 -
这就是我认为可能是问题所在.. :-/