使用下面的链接,我获得了视频的RSS提要
http://rss.cnn.com/services/podcasting/ac360/rss.xml
我需要获取此链接,并在我的网站上显示视频使用DOMDocument()在PHP。
如何从RSS提要中获取这些视频并在我的网站上显示?
以下是我的代码
$xml=("rss.cnn.com/services/podcasting/ac360/rss.xml";);
$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
for ($i=0; $i<=2; $i++) {
$item_title=$x->item($i)
->getElementsByTagName('title')
->item(0)
->childNodes
->item(0)
->nodeValue;
$item_link=$x->item($i)
->getElementsByTagName('link')
->item(0)
->childNodes
->item(0)
->nodeValue;
$item_desc=$x->item($i)
->getElementsByTagName('description')
->item(0)
->childNodes
->item(0)
->nodeValue;
echo ("<p><a href='" . $item_link. "'>" . $item_title . "</a>");
}发布于 2012-09-26 22:43:45
视频url位于<media:content>标记的url属性下,您可以使用xpath来获取这些url,如下所示:
$xml=("rss.xml");
$doc = new DOMDocument();
$doc->load($xml);
$xpath = new DOMXPath($doc);
foreach ($xpath->query('//item') as $item) {
$media = $xpath->query('//media:content', $item);
$title = $xpath->query('//title', $item);
print '<a href="'.$media->item(0)->getAttribute('url').'">'.$title->item(0)->textContent."</a>\n";
}还可以考虑使用simplepie等rss解析库。
https://stackoverflow.com/questions/12603327
复制相似问题