How can PHP be used to search through multiple files in a folder on a server for specific text or numbers?

To search through multiple files in a folder on a server for specific text or numbers, you can use PHP to loop through each file in the directory, read the contents of each file, and then search for the desired text or numbers using functions like strpos or preg_match.

<?php

$folder = 'path/to/folder'; // specify the path to the folder containing the files
$searchTerm = 'specific text or number'; // specify the text or number to search for

$files = scandir($folder);

foreach ($files as $file) {
    if (is_file($folder . '/' . $file)) {
        $contents = file_get_contents($folder . '/' . $file);
        if (strpos($contents, $searchTerm) !== false) {
            echo 'Found in file: ' . $file . '<br>';
        }
    }
}

?>