摘要:$dir = 'muban'; $findStr = 'upload_file';echo "<pre>"; /** * 读取目录,传入第二个参数查找该目录下所有文件符合该字符串 * @param $dirName&nbs
$dir = 'muban'; $findStr = 'upload_file';echo "<pre>";
/**
* 读取目录,传入第二个参数查找该目录下所有文件符合该字符串
* @param $dirName string 目录路劲
* @param $str 查找字符串,在该目录下符合的
* @return $arr,$text //返回的数组和查找的匹配文件
*/
function duquDir($dirName,$str){
$arr = [];
global $arr;
$text = [];
global $text;
$dir = opendir($dirName);
if(is_dir($dirName)){
while($row = readdir($dir)){
if($row != '.' && $row != '..'){
if(is_file($dirName.'/'.$row)){
$arr['file'][] = $dirName.'/'.$row;
//判断是否有符合的值
if($str && strpos(file_get_contents($dirName.'/'.$row),$str )){
$text[] = $dirName.'/'.$row;
}
}else{
$arr['dir'][] = $row;
$fun = __FUNCTION__;
$fun($dirName.'/'.$row,$str);
}
}
}
return $arr;
}
return $dirName.'不是目录,读取失败!!!';
}
duquDir($dir,$findStr);
print_r($arr);
echo "<h3>muban目录下文件有调用或声明函数 $findStr 的文件如下:</h3><pre>";
print_r($text);
批改老师:天蓬老师批改时间:2019-03-02 15:43:17
老师总结:从 php5.3起, 随spl同步发布很多标准类库, 就有专用于目录与文件的, 有空了解一下