0

我得到了这个结果,我想从文件夹中提取第一张图像 clear just the first

结果示例

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
4

1 回答 1

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;
于 2012-11-07T11:33:52.353 回答