php在文件夹所有文件的中查找关键词
<?php
function getDir($path)
{
if(!file_exists($path)) {
return array();
}
$files = scandir($path);
$fileItem = array();
foreach($files as $v) {
$newPath = $path .DIRECTORY_SEPARATOR . $v;
if(is_dir($newPath) && $v != '.' && $v != '..') {
$fileItem = array_merge($fileItem, getDir($newPath));
}else if(is_file($newPath)){
$fileItem[] = $newPath;
}
}
return $fileItem;
}
$root = getDir('C:\phpStudy\PHPTutorial\www\ssc\wap');
$i = 0;
foreach($root as $v){
$filecontent = @file_get_contents($v);
if(strstr($filecontent , '时时彩' )){
echo $v.'<br/>';
$i++;
}
}
echo "count file:".$i."!<br/>";
unlink($roots);