<?phpphp
set_time_limit(0);html
ini_set('memory_limit','512m');post
$path = 'D:\wamp\www\php-5.4.12';spa
$info = '';orm
if(isset($_POST['submit'])){htm
$file_arr = array();input
function scanFolder($dir,$info){it
$files = scandir($dir);io
foreach($files as $file){function
if('.' != $file && '..' != $file){
$file = $dir.DIRECTORY_SEPARATOR.$file;
if(is_dir($file)){
scanFolder($file,$info);
}else if(is_file($file)){
showRet($file,$info);
}
}
}
}
function showRet($file,$info){
global $file_arr;
$arr = file($file);
$line = 0;
foreach($arr as $text){
++$line;
if(strpos($text,$info) !== false){
echo $file,':',$line,'--',$text,'<br/>';
$file_arr[$file] = 1;
}
}
}
$path = trim($_POST['path']);
$info = trim($_POST['info']);
if(is_dir($path)){
scanFolder($path,$info);
if($file_arr){
echo '搜到的文件<br/>';
foreach($file_arr as $file=>$v){
echo $file,'<br/>';
}
}
}else{
echo $path,'is not a folder';
}
}
?>
<html>
<head>
</head>
<body>
<div class="searchBar" style="margin-top:50px;">
<form method="post" action="" >
<p>
<span>
搜索路徑:<input type="text" value="<?php echo $path;?>" name="path" />
</span>
</p>
<p align="left" style="margin-left: 200px;">
<span>
搜索內容:<input type="text" value="<?php echo $info;?>" name="info" />
</span>
</p>
<div style="margin-top: 10px;"><input type="submit" name="submit" value="提交" />
</form>
</div>
</body>
</html>