我遇到了一个问题:我必须获得第一张关于不同Feed rss项目的图片,我已经尝试过网上找到的方式,但他们都没有工作。 我认为有一个逻辑错误,我无法看到......
实际上这是我的代码:
while($dati = $stmt->fetch(PDO::FETCH_ASSOC)) //get all the urls of some feed rss from db
{
$rss = simplexml_load_file($dati['url']); //load current feeds
$items = $rss->channel->item;
$cnt = count($rss->channel->item); //number of item in current feed
for($y=0;$y<=$cnt;$y++) //check if there is an image on this item, if not, go to the next one
{
$img = (string)$rss->channel->item[0]->description;
preg_match( '@src="([^"]+)"@' , $img, $match );
$src = array_pop($match);
if($src)
break; //if an img is found exit the cicle
}