0

有人可以帮助我吗?我有许多当前名称的图片,例如:“black_abc”、“black_bcd”、“black_cde”、“white_abc”。如何仅获取文件名包含“黑色”的文件?

4

3 回答 3

2

glob将帮助您找到文件名中包含“Black”的所有文件:

$folder = "images";    //the folder containing all your images
$pattern = "*Black*";  //the word you are looking for

$files = glob($folder. '/' . $pattern, GLOB_BRACE);
foreach($files as $filename) {
  //Display all pictures
  echo "<img src='"$folder . "/" . $filename . "' />";
}
于 2013-10-09T09:53:23.197 回答
0
strpos($filename, 'black') !== false
于 2013-10-09T09:53:10.310 回答
0

像这样的东西[利用stripos()[不区分大小写]

<?php
$files=array("black_1","white_2","black_3");

for($i=0;$i<count($files);$i++)
{
if(stripos($files[i],'black'))
{
    echo "Filename is $files[$i]";
}
} 
于 2013-10-09T09:53:17.683 回答