【问题标题】:simplexml to read enclousure html tag [duplicate]simplexml 读取附件 html 标记 [重复]
【发布时间】:2014-08-29 13:45:31
【问题描述】:

如何使用 simplexml 读取 iTunes RSS 中的附件 url 标签?

饲料:

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">

<channel>
<item>
   <itunes:subtitle> subtitle </itunes:subtitle>
   <enclosure url="http://www.myWe/mySound.mp3" length="624557" type="audio/mp3"/>
</item>
</channel>
</rss>

PHP:

foreach ($feed->channel->item as $item) {
    $iTunes_item = $item->children('http://www.itunes.com/dtds/podcast-1.0.dtd');

    $item_subtitle = $item->subtitle->attributes();
    $item_url = $iTunes_item->enclosure->attributes('url'); // enclosure url

    echo $item_subtitle;
    echo $item_url;
}

【问题讨论】:

  • rss->channel->item->enclosure->attributes()->url 我认为应该得到 url。
  • @Matt:是的!这是正确的答案。谢谢
  • 为什么会有负面影响?我在 Google 和 simplexml 文档中查看了很多时间,但找不到答案。在这里问这个有什么问题?
  • php.net/manual/en/simplexml.examples-basic.php - 除了先阅读手册,然后在 google 中搜索,别忘了也搜索 stackoverflow。 ——你所说的负面观点只是对问题的否定,所以要根据社区评论对问题进行评分。这在stackoverflow上很常见,孤立的,多余的,询问我如何没有准备好的场景和具体的编程问题,要求教程/寻求辅导帮助-为什么此代码工作墙不掉-并且类似的得到评价。

标签: php xml rss simplexml


【解决方案1】:

访问网址使用;

rss->channel->item->enclosure->attributes()->url

试试这个获取字幕;

$namespaces = $item->getNameSpaces(true);
$nodes = $item->children($namespaces['itunes']);
echo $nodes->subtitle;

【讨论】:

  • 令我惊讶的是,它在没有 iTunes 地址的情况下也能正常工作。这可以应用于例如标签吗?: 例如,如果没有 iTunes 地址,这将不起作用: $feed->channel->item->subtitle->attributes();
  • 您已经很好地回答了这个问题。但是,我更新了这个问题。你知道怎么读字幕吗?好像同样不能适用?
  • 更新了答案@Nrc
  • 不,它不适用于字幕。看来它需要 iTunes 命名空间
  • 效果很好。这是太棒了。你能解释一下吗。我正在努力学习和搜索这方面的信息。
猜你喜欢
  • 2013-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-07
  • 1970-01-01
  • 2013-06-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多