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

Sir*_*jik 1 rss image extract magpie

我使用PHP和喜鹊,并希望在饲料项目中检测图像的一般方法.我知道有些网站会在机箱标签中放置图像,其他网站会像图像[rss]一样,有些网站会将其添加到说明中.是否有任何一个具有一般功能,用于检测rss项目是否具有图像并在被magpie解析后提取图像URL?

我认为需要从描述中提取reqular表达式,但在那些时候我是一个菜鸟.如果可以的话请帮忙.

Flu*_*ten 5

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

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

<enclosure url="http://www.mysite.com/myphoto.jpg" length="14478" type="image/jpeg" />
Run Code Online (Sandbox Code Playgroud)

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

    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
   ...
}
Run Code Online (Sandbox Code Playgroud)

图像的网址在$ myRSSitem ['enclosure_url']中,大小在$ myRSSitem ['enclosure_length']中.请注意,机箱标签可以引用多种类型的介质,因此首先通过检查$ myRSSitem ['enclosure_type']来检查类型是否实际上是图像.

也许其他人有一个更好的建议,我相信这可以更优雅地从其他空标签中获取属性,但我需要快速修复(截止日期的压力),但我希望这可以帮助困难的其他人!