bux23 of Micons
4/26/2017 - 10:41 AM

find string in file (search in directory and subdirectories) php

find string in file (search in directory and subdirectories) php

<?php

$string = 'stringToSearch';

$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 />";
    }
}


?>