Home  >  Article  >  Backend Development  >  php查找文件夹下文件内容

php查找文件夹下文件内容

WBOY
WBOYOriginal
2016-06-23 13:40:481530browse

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

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

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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn