php - Zend_Feed 访问项 - ATOM

标签 php zend-framework zend-feed

我正在尝试阅读“itunes RSS Feed”。据我所知它是基于 ATOM 的。

工作正常:

    $feed = $this->getFeed(self::TOP300_PAYED);

    foreach ($feed as $item) {
        echo $item->name;
    }

但我需要以下节点:

<im:image height="53">
http://a3.mzstatic.com/us/r1000/116/Purple/61/9b/f2/mzl.wyuzxxzw.53x53-50.png
</im:image>

知道如何使用 zend feed 访问它吗?

最佳答案

与任何其他 ATOM feed 一样,您可以像这样迭代它:

    $feed = new Zend_Feed_Atom("example.com");
    foreach ($feed as $entry) {
        $xml = $entry->saveXml();
        $xmlObj = simplexml_load_string($xml);

        $xmlObj->registerXPathNamespace('im', "example.com");
        $result = $xmlObj->xpath('//im:image');

        foreach ($result as $image) {
          echo $image . "\n";
        }
    }

注意 registerXPathNamespace() 的使用在这里,iTunes 似乎在其 feed 中使用了命名空间,这就是您需要先注册它的原因。

试试这个,让我知道它是否有效。

关于php - Zend_Feed 访问项 - ATOM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10143599/

相关文章:

php - 有没有更 Eloquent 方法来执行这些 MySQL 查询?

javascript - 在加载页面上,在 div 中显示 PHP 文件,然后单击在同一 div 中显示其他 PHP 文件

php - Zend 工具创建操作无法识别模块中的 Controller

php - 使用 Zend Framework 构建 REST API 服务器的示例?

php - 使用 Zend_Feed 在 Php 中通过 url 获取 Rss 版本

php - 我应该如何将盐合并到我的密码哈希中?

php - Symfony 2.1 - 在 Controller 中切换 Monolog channel

php - 从多对多表中检索对应和不对应的值

php - 使用 Zend_Feed_Reader 的 RSS 命名空间

zend-framework - Zend_Feed_Reader 异常 : Read timed out after 10 seconds