您的两个选项是DirectoryIterator或glob:
$string = 'something';
$dir = new DirectoryIterator('some_dir');
foreach ($dir as $file) {
$content = file_get_contents($file->getPathname());
if (strpos($content, $string) !== false) {
// Bingo
}
}
$dir = 'some_dir';
foreach (glob("$dir/*") as $file) {
$content = file_get_contents("$dir/$file");
if (strpos($content, $string) !== false) {
// Bingo
}
}