码迷,mamicode.com
首页 > Web开发 > 详细

php查找文件夹下文件内容

时间:2015-01-28 14:48:16      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:php   正则表达式   文件查找   搜索   

<?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>";}?>

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

<?php
error_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>";//注意添加了前后两条斜线 不然会出错
}
?>


php查找文件夹下文件内容

标签:php   正则表达式   文件查找   搜索   

原文地址:http://blog.csdn.net/qq754406613/article/details/43228467

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!