Well, you can use [man]glob/man to get all files of a particular type. As long as you're not reading a specific kind of document (PDF, MS Word, Excel, etc.) you can use [man]file_get_contents/man and then run a search on that.
For example, if I had a folder called "files" and in it was an unknown number of folders and files, I might do this:
<?php
$dir = './files';
$relevant = array();
$search = '~[a-z]~iUs';
$dirs = glob('*', GLOB_ONLYDIR); // Only get directory names
// Make all the "sub directories" have "./files/" prepended to them
array_walk($dirs, create_function('&$d,$key', 'global $dir; $d=$dir."/".$d;'));
// add the initial dir to the $dirs list...
$dirs = array_merge(array($dir), $dirs);
// Loop through each one, opening files as we go
// Save which file has some content that's relevant
foreach($dirs as $dir)
{
$files = glob('*.txt');
foreach($files as $file)
{
$contents = file_get_contents($dir.'/'.$file);
if(preg_match($search, $contents))
$relevant[$dir][] = $file;
}
}
print_r($relevant);
Not guaranteed to work, and my search string will match anything that contains any word, so it's pretty useless. But it's the basic outline of how to search directories and files. It's one of a few solutions.