PHP access to iTunes tags in an RSS feed
Asked Answered
C

5

3

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

Candiecandied answered 5/10, 2008 at 0:16 Comment(0)
C
1

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
  }
}
Connelly answered 20/12, 2008 at 4:45 Comment(1)
Doug, First it's an honer to have you answer my question. I'm a big fan of your work all around. This code worked great for me. Thanks GlennCandiecandied
R
2

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

Roo answered 5/10, 2008 at 2:33 Comment(0)
C
1

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
  }
}
Connelly answered 20/12, 2008 at 4:45 Comment(1)
Doug, First it's an honer to have you answer my question. I'm a big fan of your work all around. This code worked great for me. Thanks GlennCandiecandied
P
1

To get the attribute with SimpleXML, instead:

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

Use:

$category_text = $channel_itunes->category->attributes()->text;
Propulsion answered 31/7, 2018 at 7:47 Comment(0)
M
0
<?php echo $feed_item->children('itunes', true)->image->attributes()->href;?>
Multilateral answered 9/2, 2022 at 10:30 Comment(0)
M
-1

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

Mediatize answered 5/10, 2008 at 0:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.