2011-01-27 39 views
0

目前我的工作了SimplePie RSS閱讀器,其中我在<content:encoded>標籤如何從rss獲取信息?

http://devilsworkshop.org/feed 

此獲取本次圖像是URL我從中獲取 我寫了這個代碼

<?php 
       error_reporting(E_ALL & ~E_DEPRECATED); 
       include_once('../my_done_work/simplepie.inc'); 
       $feed = new SimplePie(); 
       $feed->set_feed_url('http://devilsworkshop.org/feed'); 
       $feed->init(); 
       $feed->handle_content_type(); 


    function returnImage ($text) 
{ 
     $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8'); 
     $pattern = "/<img[^>]+\>/i"; 
     preg_match($pattern, $text, $matches); 
     $text = $matches[0]; 
     return $text; 
} 


function scrapeImage($text) 
{ 

     $pattern = '/src=[\'"]?([^\'" >]+)[\'" >]/'; 
     preg_match($pattern, $text, $link); 
       $link = $link[1]; 
       $link = urlencode($link); 

     return $link; 

} 
$count = 0; 
       $arrImg = array(); 
       $arrtitle = array(); 
        foreach ($feed->get_items() as $kk=> $item) { 
         $feedDescription = $item->get_content(); 
         $feedTitle = $item->get_title(); 
         $image = returnImage($feedDescription); 
         $image = scrapeImage($image); 
         $image = urldecode($image); 
         $arrimg[$count] = $image; 
         $arrtitle[$count] = $feedTitle; 
         $jj = $kk+1; 
       echo '<li><a href="#"><img src="' .$arrimg[$kk]. '" id="remove" ><span>'.$arrtitle[$kk].'</span></a></li>'; 

         $count++; 

       } 

?> 
圖像

但它並沒有給我所有的圖像,但只有10個。

請大家幫忙。

謝謝。

+0

也許這是因爲Feed只能返回10個項目?如果這不是問題,您能準確描述圖像處理終止的位置以及問題是什麼? – 2011-01-27 11:37:30

回答

0

您必須使用preg_match_all而不是preg_match來獲取字符串中的所有正則表達式匹配。