我想在文件夹中获取所有’_img’和PDF类型的文件
而不是使用
$fileArray = scandir($dir); foreach ($fileArray as $file) { if (preg_match("_img",$file) && pathinfo($file,PATHINFO_EXTENSION) == 'pdf'){ $filteredArray[] = $file; } }
有没有捷径或者这是最好的方式?谢谢
解决方法
使用PHP
glob()功能
The glob() function searches for all the pathnames matching pattern according to the rules used by the libc glob() function,which is similar to the rules used by common shells
<?PHP $filteredArray = array(); foreach (glob($dir."/*_img.pdf") as $filename) $filteredArray[] = $filename; ?>