首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用magpie从rss/atom提要中提取图像

使用magpie从rss/atom提要中提取图像
EN

Stack Overflow用户
提问于 2010-08-16 13:13:15
回答 1查看 2.7K关注 0票数 0

我正在使用php和喜马拉雅,并希望在饲料项目中检测图像的一般方法。我知道一些网站将图片放在附件标签中,其他网站像这样的images[rss],还有一些只是简单地添加到描述中。有没有一个通用的功能,可以检测rss项目是否有图片,并提取图片url后,将其解析后的喜马拉雅?

我认为从描述中提取规则表达式是必要的,但我对此一无所知。如果可以的话,请帮助我。

EN

回答 1

Stack Overflow用户

发布于 2010-11-21 11:46:56

我自己花了很长时间寻找一种在RSS中通过Magpie显示图像的方法,最后我不得不检查代码来弄清楚如何让它工作。

就像你说的,在元素中没有抓取图像的原因是因为它们是使用'enclosure‘标签指定的,这个标签是一个空标签,其中信息在属性中,例如

代码语言:javascript
复制
<enclosure url="http://www.mysite.com/myphoto.jpg" length="14478" type="image/jpeg" />

为了让它为我快速工作,我在rss_parse.inc中添加了以下几行代码:

代码语言:javascript
复制
    function feed_start_element($p, $element, &$attrs) {
   ...
   if ( $el == 'channel' )
   {
      $this->inchannel = true;
   }
   ...

   // START EDIT - add this elseif condition to the if ($el=xxx) statement.
   // Checks if element is enclosure tag, and if so store the attribute values
   elseif ($el == 'enclosure' ) {
      if ( isset($attrs['url']) ) {
         $this->current_item['enclosure_url'] = $attrs['url'];
         $this->current_item['enclosure_type'] = $attrs['type'];
         $this->current_item['enclosure_length'] = $attrs['length'];
      }
   }
   // END EDIT
   ...
}

镜像的url在$myRSSitem‘’enclosure_url‘中,大小在$myRSSitem’‘enclosure_length’中。请注意,附件标记可以引用许多类型的介质,因此首先通过检查$myRSSitem' enclosure _ type‘来检查该类型是否实际上是一个映像。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3490740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档