2010-08-16 93 views
1

进出口使用PHP和鹊,并希望在饲料产品检测图像的一般方法。我知道一些网站将图片放置在机箱标签中,其他人喜欢这个images[rss],有些网站只是将其添加到说明中。是否有任何一个具有通用功能,用于检测rss项目是否具有图像,并在经过喜鹊解析后提取图像url?从RSS/ATOM拉图像饲料使用鹊RSS

我觉得reqular表达式将需要从描述中提取,但在那些我是个菜鸟。如果可以的话请帮忙。

回答

4

我花了年龄在寻找通过喜鹊RSS显示图像自己的一种方式,并在最后我不得不检查代码,以弄清楚如何得到它的工作。

像你说的,喜鹊不会在元素拿起图像的原因是因为他们使用的是“圈地”的标签,这是一个空的标签,其中的信息是在特定的属性,例如

<enclosure url="http://www.mysite.com/myphoto.jpg" length="14478" type="image/jpeg" /> 

一劈得到它为我迅速开展工作,我添加以下代码行到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 
    ... 
} 

的URL图像是$ myRSSitem [“enclosure_url” ],大小在$ myRSSitem ['enclosure_length']中。 注意机箱标签可以指多种类型的介质,所以首先检查,如果该类型实际上是通过检查$ myRSSitem [“enclosure_type”]的图像。

也许别人有更好的建议,我敢肯定这可以做得更优雅,从其他空标签中获取属性,但我需要快速修复(截止期限压力),但我希望这可能有助于其他人困难!

+0

该解决方案完美地工作为我自己凌乱的情况。非常感谢你。 – 2012-03-24 17:04:49