PHP 访问 RSS 提要中的 iTunes 标签

发布于 2024-07-06 21:26:03 字数 1066 浏览 6 评论 0原文

我需要使用 PHP 访问 RSS 源中的 iTunes 标签。 我之前曾使用 simplepie 来获取播客提要,但我不确定如何使用它来获取 iTunes 标签。 有没有办法使用 simplepie 来做到这一点,或者有更好的方法吗?


好的,我尝试了简单 XML。

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

$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:

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

我希望能够通过以下方式获取类别:

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

但这似乎不起作用。

我已经看到了其他代表该类别的方法,但我真的不知道该找谁。

例如:

技术 商业 教育

这是媒体的事还是itunes 的事,还是两者兼而有之?

感谢您的帮助。 G

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?


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;

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'];

But that does not seem to work.

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

For example:

Technology
Business
Education

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

Thanks For Your Help.
G

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

旧人 2024-07-13 21:26:03

SimplePie 有一个 get_item_tags() 函数,应该可以让您访问它们。

SimplePie has a get_item_tags() function that should let you access them.

煞人兵器 2024-07-13 21:26:03

这段代码对我有用:

//$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
  }
}

This code works for me:

//$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
  }
}
枕梦 2024-07-13 21:26:03

要使用 SimpleXML 获取属性,请改为:

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

使用:

$category_text = $channel_itunes->category->attributes()->text;

To get the attribute with SimpleXML, instead:

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

Use:

$category_text = $channel_itunes->category->attributes()->text;
虚拟世界 2024-07-13 21:26:03
<?php echo $feed_item->children('itunes', true)->image->attributes()->href;?>
<?php echo $feed_item->children('itunes', true)->image->attributes()->href;?>
九厘米的零° 2024-07-13 21:26:03

如果您有 PHP5,使用简单 XML 可以帮助解析您需要的信息。

If you have PHP5, using Simple XML can help in parsing the info you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文