I have around 100 .php files in one directory and I'm looking for one small function, what's the fastest way to search trough all contents of these files?
[edit]
I'm using Windows 7 Ultimate/NuSphere PhpED.
You can open current file in browser using following methods: Click the button Open In Browser on StatusBar. In the editor, right click on the file and click in context menu Open PHP/HTML/JS In Browser. Use keybindings Shift + F6 to open more faster (can be changed in menu File -> Preferences -> Keyboard Shortcuts )
The scandir() function returns an array of files and directories of the specified directory.
It is possible to insert the content of one PHP file into another PHP file (before the server executes it), with the include or require statement. The include and require statements are identical, except upon failure: require will produce a fatal error (E_COMPILE_ERROR) and stop the script.
php $searchthis = "mystring"; $matches = array(); $handle = @fopen("path/to/inputfile. txt", "r"); if ($handle) { while (! feof($handle)) { $buffer = fgets($handle); if(strpos($buffer, $searchthis) !== FALSE) $matches[] = $buffer; } fclose($handle); } //show results: print_r($matches); ?>
Try this:
<?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');
?>
Use your php editors "find in files" function.
Invaluable.
edit PHPNuSphere totally supports this. you need to learn some google fu brother.
If your editor doesn't have this, you need to switch ASAP.
https://stackoverflow.com/search?q=php+editor
Install cgywin - then you can use grep!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With