2012-05-18 28 views
0

我正在使用此代碼來打印原子網絡飼料。我如何訪問鏈接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> 

回答

0

對不起手機IM上,所以我不能語法它

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

既然你有更多然後1個鏈接的是很奇怪的回聲$兒童安全>鏈接