November 2nd, 2012, 12:07 PM
Search a list of files for key words
I have a series of files that I have to search for certain key words. I have the key words in a mysql table and have the file path/name in another table. Is there a way to search for the key words, looping through each file and then looping through each key word and when a match is found write the file name and key word to a mysql table?
The files I want to search are imap email files and need to search them for key words. I didn't know if using grep was possible or just using strpos after getting the file contents would be adequate.
Any help would be appreciated.
November 2nd, 2012, 12:32 PM
I'd say using 'preg_grep' would be the easiest way. Read each file into an array using explode with new line character as the delimiter then check it with 'preg_grep').
There are 10 kinds of people in the world. Those that understand binary and those that don't.
November 2nd, 2012, 08:07 PM
From what I've read preg_grep uses a regex pattern for the match. Could you give me a code example using it with a file and how to use the explode function.
Originally Posted by gw1500se