PHP to search inside 30,000 text files

拈花ヽ惹草 提交于 2019-12-23 02:32:41

问题


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?


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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




回答5:


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.



来源:https://stackoverflow.com/questions/3170201/php-to-search-inside-30-000-text-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!