PHP访问RSS源中的iTunes标签

时间:2022-06-01 01:42:45

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?

我需要使用PHP访问RSS提要中的iTunes标签。我以前使用simplepie播放播客,但我不知道如何使用它来获取iTunes标签。有没有办法使用simplepie来做或有更好的方法?


Okay I tried Simple XML.

好的,我尝试过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类别。似乎以几种方式表现出来。在这种情况下,我得到以下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?

这是媒体还是itunes或两者兼而有之?

Thanks For Your Help. G

谢谢你的帮助。 G

4 个解决方案

#1


0  

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

#2


0  

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

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

#3


0  

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

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

#4


0  

To get the attribute with SimpleXML, instead:

要使用SimpleXML获取属性,请:

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

Use:

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

#1


0  

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

#2


0  

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

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

#3


0  

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

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

#4


0  

To get the attribute with SimpleXML, instead:

要使用SimpleXML获取属性,请:

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

Use:

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