Hello my friend...
I don't know if it's possible in your specific case, but, why don't you try some index engine software as HTDIG? It can do this work for you. It's free and easy to use. You can index how many dirs as you want, doesn't matter how many files each one has. Take a look at www.htdig.org and find out if it can be useful for you.
If you really have to do this work using PHP, the way is to make a script that open and read each file seeking the key word typed. It can work well, but only if the dir has just a limited number of files.
I hope I'd been useful.
regards,
samuel