php查找文件夹下文件内容

来源:互联网 发布:vb exe反编译工具 编辑:程序博客网 时间:2024/06/05 00:39
<?php <pre name="code" class="php">error_reporting(0);//这个最好加上 因为file_get_contents遇到目录时会出错
$key=$_GET['key'];$dir=dirname(__FILE__);$file=scandir($dir);foreach($file as $f){$tmp=file_get_contents($f,1024*100);if(stripos($tmp,$key))echo $f."<br>";}?>

还可以这样:(基于正则表达式匹配)

<?phperror_reporting(0);$key=$_GET['key'];$dir=dirname(__FILE__);$file=scandir($dir);foreach($file as $f){$tmp=file_get_contents($f,1024*100);if(preg_match("/".$key."/",$tmp))echo $f."<br>";//注意添加了前后两条斜线 不然会出错}?>


0 0
原创粉丝点击