2011-08-25 76 views
3

我在一个目录中有大约100个.php文件,我正在寻找一个小功能,搜索这些文件的所有内容的最快方法是什么?如何搜索多个.php文件?

我正在使用Windows 7旗舰版/ NuSphere PhpED。

+1

如果你有Linux或Mac - 你可以使用['grep'(http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_02.html)。如果你有窗户,你可以使用[wingrep](http://www.wingrep.com/)。有些编辑还有一个“在目录中查找文本”功能,但这取决于您使用的是什么。 – birryree

+0

[grepWin(http://tools.tortoisesvn.net/grepWin.html) – tttony

+0

是指这个项目:https://github.com/skfaisal93/AnyWhereInFiles –

回答

6

使用你的php编辑器“在文件中查找”功能。

无价。

编辑PHPNuSphere完全支持这一点。你需要学习一些谷歌福兄弟。

如果你的编辑器没有这个,你需要尽快切换。 https://stackoverflow.com/search?q=php+editor

Find in files in Visual Studio

Find in files in Notepad++

+0

我使用NuSphere的PhpED,我不知道这是否有这个功能。 – Wordpressor

+0

确实如此。 http://www.nusphere.com/products/php_editor_find_text.htm –

+0

事实上,我从来没有在我的PHP编辑器中曾有过这样的功能,还想着完全不同的解决方案,像CMD相关的东西或一个PHP函数。而我所需要的仅仅是两次点击; /非常感谢! – Wordpressor

5

试试这个:

<?php 
function getFilesWith($folder, $searchFor, $extension = 'php') { 

    if($folder) { 
     $foundArray = array(); 
     // GRAB ALL FILENAMES WITH SUPPLIED EXTENSION 
     foreach(glob($folder . sprintf("*.%s", $extension)) as $file) { 
      $contents = file_get_contents($file); 

      if(strpos($contents, $searchFor) !== false) { 
       $foundArray[] = $file; 
      } 
     } 

     if(count($foundArray)) { 
      return $foundArray; 
     } else { 
      return false; 
     } 
    } else { 
     return false; 
    } 
} 

$matched_files = getFilesWith('path/to/folder', 'Looking for this'); 
?> 
+1

我的意思是,我赞扬了这一努力,但这是矫枉过正! – birryree

+1

@birryree在具有有限的访问共享主机,这是可以肯定它会工作 –

+1

我同意...与代码搜索时,如果我们只有FTP访问,不希望下载的所有文件所需的唯一途径... ... –

0

对于Windows我会安装cygwin和使用find或grep的,但做不到这一点

  • 安装总指挥官,使用Alt + F7递归搜索。还有在多个文件中选择一个替代 - http://www.ghisler.com 你会不知道怎么过导航系统它

  • 使用Notepad++可以打开所有文件,做一个普通的文本搜索只是检查在所有打开的文件框”的搜索无“

1
function search_in_dir($dir, $str) 
{ 
    $files = glob("{$dir}/*.php"); 
    foreach($files as $k => $file) 
    { 
     $source = file_get_contents($file); 
     if(strpos($source, $str) === false) 
     { 
      unset($files[$k]); 
     } 
    } 
    return array_filter($files); 
} 
$files = search_in_dir('dir/files', 'my string'); 
3

安装cgywin - 那么你可以使用grep!

+0

这将是我的答案! +1 – Drewdin