PHP快速搜索代码以更快定位修改点

 

请放在根目录下的文件夹下使用
推荐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("<","&lt;",$linex);
      $linex = str_replace(">","&gt;",$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";
}
?>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YUJIANYUE

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值