bux23
9/6/2017 - 8:57 AM

Search string in files

Search for string in files recursively

<?php

$string = 'webfont';
$folder = 'wp-test';

if (file_exists($folder)) {
	$dir = new RecursiveDirectoryIterator($folder);
	foreach (new RecursiveIteratorIterator($dir) as $filename => $file) {
	    //$thename = $file->getFilename(); //uncomment this line and next to print names of all files scanned
	    //echo $thename.'<br />';
	    $content = file_get_contents($file->getPathname());
	    if (strpos($content, $string) !== false) {
	        echo "<br /><b>string found in file: ".$file->getPathname()."</b><br /><br />";
	    }
	}
} else {
	echo 'folder not found';
}

?>