请放在根目录下的文件夹下使用
推荐linuxPHP环境(5.5-7.3)
多年来一直自用的代码:请自用(文件夹和文件名自定义)以防代码泄密
仅搜索:另外还有多行替换/单行替换等不再提供:容易误操作引起不可逆损失
<style>
h1{font-size:24px;line-height:180%;font-weight:600;margin:1px 2px;color:red;}
h2{font-size:20px;line-height:140%;font-weight:600;margin:2px 4px;color:green;}
h3{font-size:16px;line-height:140%;font-weight:600;margin:2px 4px;color:green;}
h4{font-size:12px;line-height:120%;font-weight:300;margin:1px 2px;color:blue;}
b{font-size:14px;color:red;}
form{margin:11px auto;padding:10px;text-align:left;width:92%;border:1px #0180CF solid;}
button[type='submit'],input[type='submit']{background:green url(line_bg.jpg) repeat-x;color:white;}
input[type=text]{width:254px;}
input[type=submit]{width:120px;}
</style>
<?php
//请放在根目录下的文件夹下使用
//推荐linuxPHP环境(5.5-7.3)
//多年来一直自用的代码:请自用(文件夹和文件名自定义)以防代码泄密
//仅搜索:另外还有多行替换/单行替换等不再提供:容易误操作引起不可逆损失
echo "<h1>代码搜索小工具</h1>";
$domas = (isset($_GET['do']))?addslashes($_GET['do']):'';
$dokey = (isset($_POST['key']))?$_POST['key']:''; //addslashes(
if(strlen($dokey)>2){
$domts = (isset($_POST['time']))?addslashes($_POST['time']):'';
$folds = $domts.'/';
if( strlen($folds)<2 || $folds=="/"){
$folds = '';
}
}else{
?>
<form name="qu" method="post" action="" >
<select name="time" id="time" >
<?php
$dir_name = "../";
$dir = opendir($dir_name);
$fileArr = array();
while ($file_name = readdir($dir)) {
if (($file_name ==".") || ($file_name == "..")) {
} else if(is_dir($dir_name.$file_name)) {
$fName = "$dir_name$file_name";
$fTime = filemtime($fName);
$fileArr[$file_name] = $fTime;
//可以文件夹分类,选择对应的目录查询:如果不分一个文件夹即可
echo "<option value=\"{$file_name}\">$file_name</option>";
}
}
echo "<option value=\"AllFolder\">AllFolder</option>";
?>
</select>
<input name="key" type="text" value="function|echo|write" placeholder="输入关键词" />
<input type="submit" name="button" value="立即查询" />
</form>
<?php
exit();
}
function charaget($data){
if(!empty($data) ){
$fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
if( $fileType != 'UTF-8'){
$data = mb_convert_encoding($data ,'utf-8' , $fileType);
}
}
return $data;
}
function characet($data){
if(!empty($data) ){
$fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
if( $fileType != 'GBK'){
$data = mb_convert_encoding($data ,'GBK' , $fileType);
}
}
return $data;
}
function my_scandir($dir){
global $dokey;
$files = array(); $filetxt="";
if ( $handle = opendir($dir) ) {
while ( ($file = readdir($handle)) !== false ) {
if ( $file != ".." && $file != "." ) {
if ( is_dir($dir . $file. "" ) ) {
if(stristr("@".$file,"@data") || stristr("@".$file,"@logs")){
}else{
$filetxt .= my_scandir($dir . $file. "/");
}
} else{
$filep = $dir . $file;
$filet = substr($file,-3);
$filep = charaget($filep); //$dir . $file;
$filea = charaget($file);
$b = preg_replace("/[^0-9^A-Z^a-z]+/u", '', $dir);
$blacki = "-laydate.css-laydate.js-";
if(stristr("-php-css-.js-htm-tml-asp-","-{$filet}-") && !stristr($blacki,"-{$file}-")){
if (is_file($filep)){
}else{
$filep = characet($filep);
}
$filey = charaget($filep);
echo "<h3>$filey</h3>\r\n";
//################################
$strsarry = explode("|",$dokey); //多个用|隔开"conn|user|kudi"
//################################
$linea = "";
$iii=0;
$bandle = fopen($filep,'r');
if ($bandle) {
while (!feof($bandle)) {
$linex = fgets($bandle, 4096);
$iii++;
$isshow = "nos";
if (strlen($linex)>4000){
echo "<h2>行{$iii}超4K</h2>";
}else{
foreach ($strsarry as $tistr) {
$tistr = addslashes($tistr);
if(stristr($linex,$tistr)){
$isshow = "yes";
$linex = str_replace($tistr,"[b]{$tistr}[/b]",$linex);
}
}
if($isshow == "yes"){
$linex = charaget($linex);
$linex = str_replace("<","<",$linex);
$linex = str_replace(">",">",$linex);
$linex = str_replace("[b]","<b>",$linex);
$linex = str_replace("[/b]","</b>",$linex);
echo "<br>行{$iii}: $linex";
}
}
}
fclose($bandle);
}
}
}
}
}
closedir($handle);
return $filetxt;
}
}
$soudir = "../{$folds}";
if(is_dir($soudir)) {
$result = my_scandir($soudir);
}elseif($folds=="AllFolder/") {
$result = my_scandir("../");
}else{
echo "<h1>文件夹<b>{$folds}</b>不存在!</h1>\r\n";
}
?>