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();
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...