- scandir: documentation ( source)
- file_get_contents: documentation ( source)
- preg_match: documentation ( source)
- print_r: documentation ( source)
<?php
$searchQuery = "hello";
$dir = "/home/mosh/";
$files = scandir($dir);
foreach($files as $file) {
if (($file !== ".") && ($file !== "..")) {
$s = file_get_contents($file);
preg_match("/{$searchQuery}/",$s,$match);
if ($match) {
$matchedFiles[] = $file;
}
}
}
print_r($matchedFiles);