0

I'm using this code to print a atom web feed. how do i get access to one of the images in the link rel='enclosure'? can anybody help me please? I just want to print one image on my screen, but i don't know how to get access to one of the four link attributes. I already searched for information but it don't seems to help me out.

<?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>
Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Niels
  • 425
  • 5
  • 9
  • 22

1 Answers1

0

Sorry Im on a mobile phone so I cant syntax it

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

Since you got more then 1 link's is it strange to echo $child->link

EaterOfCode
  • 2,202
  • 3
  • 20
  • 33