PHP对RSS提要中的iTunes标签的访问 [英] PHP access to iTunes tags in an RSS feed

查看:64
本文介绍了PHP对RSS提要中的iTunes标签的访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用PHP来访问RSS feed中的iTunes标签.我以前使用过simplepie进行播客feed,但是我不确定如何使用它来获取iTunes标签.有没有办法使用simplepie做到这一点,还是有更好的办法?

I need to get access to the iTunes tags in an RSS feed using PHP. I've used simplepie before for podcast feeds, but I'm not sure how to get the iTunes tags using it. Is there a way to use simplepie to do it or is there a better way?

好吧,我尝试了简单XML.

Okay I tried Simple XML.

所有这些(下面的代码)似乎有效

All this (the code below) seems to work

$feed = simplexml_load_file('http://sbhosting.com/feed/');
$channel = $feed->channel;
$channel_itunes = $channel->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
$summary = $channel_itunes->summary;
$subtitle = $channel_itunes->subtitle;
$category = $channel_itunes->category;
$owner = $channel_itunes->owner->name;

现在,我需要获取iTunes类别.似乎以几种方式表示. 在这种情况下,我得到以下XML:

Now I need to get the itunes categories. The seem to be represented in several ways. In this case I get the follow XML:

<itunes:category text="Technology"/>
<itunes:category text="Technology">
  <itunes:category text="Software How-To"/>
</itunes:category> 

我希望能够获得类似以下内容的类别:

I would expect to be able to get the category with something like this:

$category_text = $channel_itunes->category['text'];

但这似乎不起作用.

我已经看到了其他方式来表示我真的不知道该获得谁的类别.

I've seen other ways to represent the category that I really don't know who to get.

例如:

技术 商业 教育

Technology Business Education

这是媒体事物还是iTunes事物,还是两者兼而有之?

Is this a media thing or a itunes thing or both?

感谢您的帮助. G

推荐答案

此代码对我有用:

//$pie is a SimplePie object
$iTunesCategories=$pie->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES,'category');
if ($iTunesCategories) {
  foreach ($iTunesCategories as $iTunesCategory) {
    $category=$iTunesCategory['attribs']['']['text'];
    $subcat=$iTunesCategory['child']["http://www.itunes.com/dtds/podcast-1.0.dtd"]['category'][0]['attribs']['']['text'];
    if ($subcat) {
      $category.=":$subcat";
    }
    //do something with $category
  }
}

这篇关于PHP对RSS提要中的iTunes标签的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆