我正在使用此代码打印原子网络Feed。如何访问链接rel ='enclosure'中的一个图像?有人可以帮我吗?我只想在屏幕上打印一个图像,但我不知道如何访问四个链接属性之一。我已经搜索了信息,但它似乎没有帮助我。
<?php
// read in an xml file
$myFile = "http://www.deredactie.be/cm/vrtnieuws?mode=atom";
$feed = simplexml_load_file($myFile);
$xml = $feed->children('http://www.w3.org/2005/Atom');
echo "<h1>".$xml->title . "</h1>\n";
foreach ($xml->entry as $entries) {
$child = $entries->children('http://www.w3.org/2005/Atom');
// post title
echo "<h3>".$child->title . "</h3>\n";
// post author
// post content
if (!empty($child->summary)) echo htmlspecialchars($child->summary) . "<br />\n";
echo $child->content->asXML();
echo $child->updated;
echo $child->link;
}
?>
<entry>
<title>400 "Blockupy"-manifestanten opgepakt in Frankfurt</title>
<summary>In Frankfurt hebben betogers voor de derde dag op rij betoogd tegen de financiële crisis en de zware besparingen. 400 mensen zijn opgepakt.</summary>
<id>http://www.deredactie.be/permalink/1.1304838</id>
<published>2012-05-18T20:14:00.000+02:00</published>
<updated>2012-05-18T20:14:00.000+02:00</updated>
<link rel="self" type="application/atom+xml" title="400 "Blockupy"-manifestanten opgepakt in Frankfurt" href="http://www.deredactie.be/permalink/1.1304838?mode=atom"/>
<link rel="alternate" type="text/html" title="vrtnieuws - 400 "Blockupy"-manifestanten opgepakt in Frankfurt" href="http://www.deredactie.be/permalink/1.1304838"/>
<link rel="enclosure" href="http://media.vrtnieuws.net/2012/05/191629155ONL1205188400687.urlFLVLong.flv" type="video/x-flv" title=""Blockupy"-protest tegen banken in Frankfurt"/>
<link rel="enclosure" href="http://media.vrtnieuws.net/2012/05/191629155ONL1205188400687_urlThumbnailDir_tmb/0050.jpg" type="image/jpeg; format=thumbnail" title=""Blockupy"-protest tegen banken in Frankfurt"/>
<link rel="enclosure" href="http://www.deredactie.be/polopoly_fs/1.1304852!image/3646472733.jpg" type="image/jpeg"/>
</entry>
答案 0 :(得分:0)
对不起,我在手机上,所以我不能语法
$result = $child->xpath('//link[@rel=\'enclosure\']');
while(list( , $node) = each($result)) {
echo "<img src='{$node['@href']}' />";
}
由于你有超过1个链接,所以回显$ child-&gt;链接
是很奇怪的