PHP 访问 RSS 提要中的 iTunes 标签
我需要使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
SimplePie 有一个
get_item_tags()
函数,应该可以让您访问它们。SimplePie has a
get_item_tags()
function that should let you access them.这段代码对我有用:
This code works for me:
要使用 SimpleXML 获取属性,请改为:
使用:
To get the attribute with SimpleXML, instead:
Use:
如果您有 PHP5,使用简单 XML 可以帮助解析您需要的信息。
If you have PHP5, using Simple XML can help in parsing the info you need.