Then the PHP function file() will read the file line by line into an array. You can search each element of that array with in_array() for your word and if found you'll then have the filename (current file opened with readdir) and the line number (file() array key plus one). You can store that to an array while you continue searching the rest of the files.