我正在使用php和喜马拉雅,并希望在饲料项目中检测图像的一般方法。我知道一些网站将图片放在附件标签中,其他网站像这样的images[rss],还有一些只是简单地添加到描述中。有没有一个通用的功能,可以检测rss项目是否有图片,并提取图片url后,将其解析后的喜马拉雅?
我认为从描述中提取规则表达式是必要的,但我对此一无所知。如果可以的话,请帮助我。
发布于 2010-11-21 11:46:56
我自己花了很长时间寻找一种在RSS中通过Magpie显示图像的方法,最后我不得不检查代码来弄清楚如何让它工作。
就像你说的,在元素中没有抓取图像的原因是因为它们是使用'enclosure‘标签指定的,这个标签是一个空标签,其中信息在属性中,例如
<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‘来检查该类型是否实际上是一个映像。
https://stackoverflow.com/questions/3490740
复制相似问题