我尝试了很多次尝试,但似乎无法将此图像中的图像转换为我的图像。我只是在寻找缩略图出现在我的Feed中。有人可以帮忙吗?
<?php
$XMLpath = 'http://feeds.bbci.co.uk/news/technology/rss.xml';
$xml = simplexml_load_file($XMLpath);
//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>';
echo '<p>'.$item->description.'</p>';
echo '<p><a href="'.$item->link.'">Read more..</a> ('.$item-
>pubDate.') </p>';
echo '<hr>';
}
&GT;
答案 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>';
}
?>