#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    15
    Rep Power
    0

    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.

    Thanks,
    Tom
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,538
    Rep Power
    595
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    15
    Rep Power
    0
    Originally Posted by gw1500se
    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').
    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.

    Thanks,
    Tom

IMN logo majestic logo threadwatch logo seochat tools logo