phpフォルダのすべてのファイルでキーワードを検索

7451 ワード

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){
	//          
	//if($v == 'C:\phpStudy\PHPTutorial\www\ssc\wap\1.php' || $v == 'C:\phpStudy\PHPTutorial\www\ssc\wap\1.txt'|| $v == 'C:\phpStudy\PHPTutorial\www\ssc\wap\2.php'){continue;}
	//          
	$filecontent = @file_get_contents($v);
	//          
	if(strstr($filecontent , '   ' )){
		//          
		echo $v.'
'
; $i++; } } echo "count file:".$i."!
"
; // unlink($roots); //