我问之前搜索过,没有幸运..
我正在为自己寻找一个可以搜索文件/文件夹的简单脚本。在 php 手册中找到了这个代码片段(我想我需要这个),但它对我不起作用。
“正在寻找一种使用掩码搜索文件/目录的简单方法。这是一个这样的功能。
默认情况下,此函数会将 scandir() 结果保存在内存中,以避免多次扫描同一目录。"
<?php
function sdir( $path='.', $mask='*', $nocache=0 ){
static $dir = array(); // cache result in memory
if ( !isset($dir[$path]) || $nocache) {
$dir[$path] = scandir($path);
}
foreach ($dir[$path] as $i=>$entry) {
if ($entry!='.' && $entry!='..' && fnmatch($mask, $entry) ) {
$sdir[] = $entry;
}
}
return ($sdir);
}
?>
感谢您的帮助,
彼得
最佳答案
$a = new RegexIterator(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator('DIRECTORY HERE')
),
'/REGEX HERE/',
RegexIterator::MATCH
);
foreach ($a as $v) {
echo "$v\n"; //$v will be the filename
}
关于php scandir --> 搜索文件/目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2861834/