0

我正在使用此代码打印 atom 网络提要。如何访问链接 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 &#034;Blockupy&#034;-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 &#034;Blockupy&#034;-manifestanten opgepakt in Frankfurt" href="http://www.deredactie.be/permalink/1.1304838?mode=atom"/>
<link rel="alternate" type="text/html" title="vrtnieuws - 400 &#034;Blockupy&#034;-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="&#034;Blockupy&#034;-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="&#034;Blockupy&#034;-protest tegen banken in Frankfurt"/>
<link rel="enclosure" href="http://www.deredactie.be/polopoly_fs/1.1304852!image/3646472733.jpg" type="image/jpeg"/>
</entry>
4

1 回答 1

0

对不起,我在手机上,所以我不能语法

$result = $child->xpath('//link[@rel=\'enclosure\']');
while(list( , $node) = each($result)) {
    echo "<img src='{$node['@href']}' />";
}

因为你有超过 1 个链接,所以回显 $child->link 很奇怪

于 2012-05-18T22:53:13.187 回答