PHP在30,000个文本文件中搜索

I have a directory of about 30,000 text files and I'd like to search inside each to find if they contain a specified text. How can I do this effectively in PHP?

grep is your friend. You can use one of php's functions that allow execution of external commands to call it, if for some reason you need the result inside a PHP script.

1) Use grep as mentioned above

2) Cache the search results so you don't have to search 30,000 text files for the same search term again.

As the others have said, grep is your friend, do a system call for it.

Also, consider building a search index using something like Lucene: http://lucene.apache.org/java/docs/index.html

are all the files going to stay as the same name? are any files going to be added, or is it set on 30,00? if all filename stay the same, and no files are going to be added, i would make an index (maybe index.txt), and explode that to get filenams for keywords.