开发者

PHP to search inside 30,000 text files

I have a directory of about 30,000 text files and I'd like to search inside each to find if they conta开发者_如何学运维in 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜