2008-10-05 66 views
1

我需要用PHP來獲得一個RSS feed訪問iTunes標籤。我之前使用過simplepie作爲播客供稿,但我不確定如何使用它獲取iTunes標籤。有沒有辦法使用simplepie來做到這一點,或者有更好的方法嗎?PHP訪問到iTunes標籤RSS供稿


好吧我試過簡單的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或兩者?

感謝您的幫助。 摹

回答

0

此代碼的工作對我來說:

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

道格, 首先,它是一個企業榮譽有你回答我的問題。我是你工作的忠實粉絲。 這段代碼對我很好。 謝謝 Glenn – gbennett 2009-04-28 05:08:56

0

如果你有PHP5,使用簡單的XML可以解析您需要的信息幫助。

+0

我不能得到這個工作。 – gbennett 2009-05-12 04:26:10