如果有人能给我一个用于获取低于文件名的glob的正则表达式模式,那将是很好的:
1.jpg // this file
1_thumb.jpg
2.png // this file
2_thumb.png
etc...
Run Code Online (Sandbox Code Playgroud)
没有"_thumb"返回文件.我有这种模式:
$numericalFiles = glob("$this->path/*_thumb.*");
Run Code Online (Sandbox Code Playgroud)
这给了我所有的"_thumb".
glob()在您处理具有复杂文件匹配要求的情况下,并不是最好的,正如您已经注意到的那样.我建议使用PHP的SPL库并利用DirectoryIterator类.
$iterator = new DirectoryIterator("/dir/path");
foreach ($iterator as $file) {
if ($file->isFile() && preg_match("/^[0-9]+\./i",$file->getFilename())) {
echo $file->getFilename();
}
}
Run Code Online (Sandbox Code Playgroud)
您可以在迭代期间干净地修改您的条件(如果您需要递归目录迭代,也可以很容易地修改迭代器).