Skip to content

Instantly share code, notes, and snippets.

@bUxEE
Last active March 19, 2024 03:25
Show Gist options
  • Save bUxEE/9403f586d513410552e2576b5d354b44 to your computer and use it in GitHub Desktop.
Save bUxEE/9403f586d513410552e2576b5d354b44 to your computer and use it in GitHub Desktop.
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 />";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment