获取媒体:来自XML的缩略图

Tom*_*eus 3 php rss xml-namespaces

我似乎无法解决这个问题.我想从RSS文件(http://feeds.bbci.co.uk/news/rss.xml)获取媒体:缩略图.

我做了一些研究,并尝试将来自/sf/ask/469512081/ 和其他来源的见解纳入其中 .

这就是我得到的:

$source_link = "http://feeds.bbci.co.uk/news/rss.xml";
$source_xml = simplexml_load_file($source_link);
$namespace = "http://search.yahoo.com/mrss/";

foreach ($source_xml->channel->item as $rss) {
    $title          = $rss->title;
    $description    = $rss->description;
    $link           = $rss->link;
    $date_raw       = $rss->pubDate;
    $date           = date("Y-m-j G:i:s", strtotime($date_raw));
    $image          = $rss->attributes($namespace);

    print_r($image);
}
Run Code Online (Sandbox Code Playgroud)

当我运行脚本时,我看到的只是一个白页.如果我回显或print_r任何其他变量,那么它就像一个魅力.它只是造成问题的$ image.为什么这不起作用?感谢任何帮助!

Tom*_*eus 6

好的,它现在有效.我换了

$image = $rss->attributes($namespace); 
Run Code Online (Sandbox Code Playgroud)

$image = $rss->children($namespace)->thumbnail[1]->attributes();
$image_link = $image['url'];
Run Code Online (Sandbox Code Playgroud)

它现在就像一个魅力.