php查找文件夹下文件内容

WBOY
Release: 2016-06-23 13:40:48
Original
1529 people have browsed it

<?php <pre name="code" class="php">error_reporting(0);//这个最好加上 因为file_get_contents遇到目录时会出错
Copy after login
$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>";//注意添加了前后两条斜线 不然会出错}?>
Copy after login


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template