How can PHP be used to search for files in a filesystem based on a specific string?

To search for files in a filesystem based on a specific string in PHP, you can use the `glob()` function along with a loop to iterate through the files in a directory and check if the string is present in each file's content. You can then store the matching files in an array for further processing.

$searchString = "example";
$files = glob('path/to/directory/*');

$matchingFiles = [];

foreach ($files as $file) {
    $fileContent = file_get_contents($file);
    if (strpos($fileContent, $searchString) !== false) {
        $matchingFiles[] = $file;
    }
}

print_r($matchingFiles);