Every linux user knows the power of grep, which saves us hours. Sometimes we need to find a string/word from html-output of a large CMS, but we dont know in which directoty/file is it. PHP-Grep helps us in this situation with searching in all directories/files under given path. /** define("SLASH", stristr($_SERVER[SERVER_SOFTWARE], "win") ? "\\" : "/"); $path = ($_POST[path]) ? $_POST[path] : dirname(__FILE__) ; function php_grep($q, $path){ $fp = opendir($path); if($q){ echo <<
HRD; ?>
* powered by @cafewebmaster.com
* free for private use
* please support us with donations
*/
$q = $_POST[q];
while($f = readdir($fp)){
if( preg_match("#^\.+$#", $f) ) continue; // ignore symbolic links
$file_full_path = $path.SLASH.$f;
if(is_dir($file_full_path)) {
$ret .= php_grep($q, $file_full_path);
} else if( stristr(file_get_contents($file_full_path), $q) ) {
$ret .= "$file_full_path\n";
}
}
return $ret;
}
$results = php_grep($q, $path);
}
$results
- Log in to post comments