2012-11-07 121 views
0

我得到了這樣的結果,我想提取文件夾第一圖像清晰而造成的搜索並從結果中刪除?

http://i.i.com.com/cnwk.1d/i/tim/2012/07/12/Les_Horribles_Cernettes_in_1992_620x350.jpg 
http://i.i.com.com/cnwk.1d/i/tim/2012/07/03/IBM-350-publicdomain_220x157.jpg 
http://cbsdigitalmedia.112.2o7.net/b/ss/cbscbsnewscomatlantisuat/1/H.21--NS.png 
http://dw.com.com/clear/c.gif 
http://i.i.com.com/cnwk.1d/i/tim/2012/07/03/IBM-350-publicdomain_220x157.jpg 
http://dw.com.com/clear/test2.gif 
http://cbsdigitalmedia.112.2o7.net/b/ss/cbscbsnewscomatlantisuat/1/H.21--NS.png 
http://dw.com.com/clear/test.gif 

的形象,我想

http://dw.com.com/clear/c.gif 
+0

鏈接如何存儲?數組?你怎麼知道你要鏈接哪個鏈接? – George

+0

@ F4r-20結果從此代碼中獲得http://stackoverflow.com/questions/13266594/get-the-first-image-in-a-page-with-class-foo –

+3

請解釋我們沒有問題了解 – Elby

回答

2

確定的第一

例子,所以我實際上是對你的問題頗有興趣..所以我想出了一些...

$firstFile; 

//This is the array with your URL values 
$imgUrls[0] = "http://i.i.com.com/cnwk.1d/i/tim/2012/07/12/Les_Horribles_Cernettes_in_1992_620x350.jpg"; 
$imgUrls[1] = "http://i.i.com.com/cnwk.1d/i/tim/2012/07/03/IBM-350-publicdomain_220x157.jpg"; 
$imgUrls[2] = "http://cbsdigitalmedia.112.2o7.net/b/ss/cbscbsnewscomatlantisuat/1/H.21--NS.png"; 
$imgUrls[3] = "http://dw.com.com/clear/c.gif"; 
$imgUrls[4] = "http://i.i.com.com/cnwk.1d/i/tim/2012/07/03/IBM-350-publicdomain_220x157.jpg"; 
$imgUrls[5] = "http://dw.com.com/clear/test2.gif"; 
$imgUrls[6] = "http://cbsdigitalmedia.112.2o7.net/b/ss/cbscbsnewscomatlantisuat/1/H.21--NS.png"; 
$imgUrls[7] = "http://dw.com.com/clear/test.gif"; 

//This foreach loop goes through the array and checks the containing directory 
foreach($imgUrls as $value){ 
    $urlParts = explode("/",$value); 
    if($urlParts[count($urlParts)-2] == "clear"){ 
     $firstFile = $value; 
     break; 
    } 
} 

//After setting $firstFile as the Image URL, echo it out. 
echo $firstFile;