微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 如何从RSS itunes中读取图像标签

我尝试阅读我的iTunes RSS.我可以阅读标题,甚至是itunes:字幕,但我的标签图片有问题.

饲料:

<?xml version="1.0" encoding="UTF-8"?>
<RSS xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">

<channel>
<title>title of the podcast</title>  
<itunes:image href="http://www.MyWeb/myImg.png"/>
</channel>
</RSS>

PHP

$xml=("http://www.myWeb/RSS.xml");
$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);

$channel=$xmlDoc->getElementsByTagName('channel')->item(0);

$channel_title = $channel->getElementsByTagName('title')//normal tag
->item(0)->childNodes->item(0)->nodeValue;

$channel_image = $channel->getElementsByTagName('image') //problem
->item(0)->childNodes->item(0)->nodeValue;

echo $channel_title . '<br>';
echo $channel_image . '<br>';

解决方法:

你可以使用SimpleXML.因为image元素有一个名称空间前缀(itunes),所以你必须使用children方法传递名称空间URL,然后调用attributes方法

$Feed = simplexml_load_file('http://www.myWeb/RSS.xml');
foreach ($Feed->channel as $channel) {
  $ns_itunes = $channel->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
  echo $ns_itunes->image->attributes();
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐