Jump to content


Photo

Search within PHP files


  • Please log in to reply
3 replies to this topic

#1 dan182skater

dan182skater
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 21 June 2006 - 04:43 AM

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

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 21 June 2006 - 06:06 AM

You could use glob() - file() - strpos()

#3 dan182skater

dan182skater
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 27 June 2006 - 03:48 AM

thanks for the reply, but that made no sense to me.

#4 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 27 June 2006 - 06:46 AM

[!--quoteo(post=388343:date=Jun 27 2006, 04:48 AM:name=dan182skater)--][div class=\'quotetop\']QUOTE(dan182skater @ Jun 27 2006, 04:48 AM) View Post[/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...
<?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>";
    }
}
?>
This is untested, so I'm not sure if it would work. Failingthis, doesn't Windows "find" search within files?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users