What function can be used in PHP to search for specific files in a directory?

To search for specific files in a directory in PHP, you can use the `glob()` function. This function allows you to search for files using wildcards or patterns in a specified directory. You can then loop through the results to process the files as needed.

$directory = "/path/to/directory";
$searchPattern = "*.txt";

$files = glob($directory . '/' . $searchPattern);

foreach($files as $file){
    echo $file . "<br>";
}