Jump to content

Archived

This topic is now archived and is closed to further replies.

dan182skater

Search within PHP files

Recommended Posts

Hello, I have a folder of like 300 PHP files and want to search for a specific line of code that would only be in one of the files. The problem is I don't have time to open each of the 300 files and search for the code. Is there a way a program that lets me search within all the PHP files to find that line of code? Or at least find the file that the line of code would be in? THANKS!

-Daniel

Share this post


Link to post
Share on other sites
You could use glob() - file() - strpos()

Share this post


Link to post
Share on other sites
[!--quoteo(post=388343:date=Jun 27 2006, 04:48 AM:name=dan182skater)--][div class=\'quotetop\']QUOTE(dan182skater @ Jun 27 2006, 04:48 AM) [snapback]388343[/snapback][/div][div class=\'quotemain\'][!--quotec--]
thanks for the reply, but that made no sense to me.
[/quote]
I meant you could write a script with the PHP functions I listed to search your files. Something like this...
[code]<?php
foreach(glob("dir/to/files/*.php") as $f) {
    $lines = file($f);
    foreach($lines as $l) {
        if(strpos($l,"I am looking for this in my code") !== FALSE) echo "<p>WE HAVE A MATCH IN $f</p>";
    }
}
?>[/code]
This is untested, so I'm not sure if it would work. Failingthis, doesn't Windows "find" search within files?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.