Quantcast
Channel: Getting pictures to display from an XML feed - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Jeff Puckett for Getting pictures to display from an XML feed

$
0
0
<?php

$XMLpath = 'http://feeds.bbci.co.uk/news/technology/rss.xml';


$xml = simplexml_load_file($XMLpath);
$ns = $xml->getNamespaces(true);

//Title of feed

echo '<h3>'.$xml->channel->title.'</h3>';
echo '<h3>'.$xml->channel->description.'</h3>';
echo '<p>'.$xml->channel->date.'</p>';
echo '<hr>';

// Feed content

 foreach( $xml->channel->item as $item ) {

    //var_dump($item);

echo '<h3>'.$item->title.'</h3>';
$thumbnail=$item->children($ns["media"]);
if(!empty($thumbnail)){
  $thumbnail_attrs=$thumbnail->thumbnail[1]->attributes();
  $image=$thumbnail_attrs["url"];
  echo "<img src='$image'></img>";
}
echo '<p>'.$item->description.'</p>';
echo '<p><a href="'.$item->link.'">Read more..</a> ('.$item->pubDate.') </p>';
echo '<hr>';

}
?>

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>