Searching for a text string in all files and directories recursively in PHP

Sometimes you need to edit some part of your website and unfortunately it isn’t made by you. You will, obviously, need to search for the file in which that particular part of site exists. In CMSs/forums/blogs, it get really hard to search it manually.

I was having a similar problem. I needed to edit the footer of my site but I didn’t know which file, out of 100s, had that particular part. I just made a script for that.



$query="find . -exec grep -l $query {} ;";



Save this file as textsearch.php in your root directory. Now visit the site

And voila! You get the results.


DisclaimerPlease note that this should be used only by webmasters as a quick tool to find specific strings within all files without having to download all the files to local computer. While this method is not recommended, this can be used as a temporary tool only. This file (textsearch.php) should be deleted as soon as your work is done with it for security reasons. I won’t be held responsible for any damages caused.

Leave a comment

Your email address will not be published.