Last active
March 19, 2024 03:25
-
-
Save bUxEE/9403f586d513410552e2576b5d354b44 to your computer and use it in GitHub Desktop.
find string in file (search in directory and subdirectories) php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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