搜索并从结果中删除?

时间:2012-11-07 10:55:37

标签: php

我得到了这个结果,我希望从第一个文件夹清除第一个图像

结果示例

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

1 个答案:

答案 0 :(得分: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;