它返回一個含有所有文件的列表包含搜索詞語數(shù)組。

復制代碼 " /> 日本另类视频,电影一区二区,国产精品久久国产三级国电话系列

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

Search File Contents PHP 搜索目錄文本內(nèi)容的代碼

這個類可以用來搜索在給定的文本目錄中的文件。
它可以給定目錄遍歷遞歸查找某些文件擴展名的文件。
并打開找到的文件,并檢查他們是否包含搜索詞語。

它返回一個含有所有文件的列表包含搜索詞語數(shù)組。

復制代碼 代碼如下:
<?php
/*
Class for searching the contents of all the files in a directory and its subdirectories
For support please visit http://www.webdigity.com/
*/
class searchFileContents{
var $dir_name = '';//The directory to search

var $search_phrase = '';//The phrase to search in the file contents
var $allowed_file_types = array('php','phps');//The file types that are searched
var $foundFiles;//Files that contain the search phrase will be stored here
//開源代碼OSphp.COM.Cn
var $myfiles;
function search($directory, $search_phrase){
$this->dir_name = $directory;
$this->search_phrase = $search_phrase;

$this->myfiles = $this->GetDirContents($this->dir_name);
$this->foundFiles = array();
if ( empty($this->search_phrase) ) die('Empty search phrase');

if ( empty($this->dir_name) ) die('You must select a directory to search');
foreach ( $this->myfiles as $f ){
if ( in_array(array_pop(explode ( '.', $f )), $this->allowed_file_types) ){ //開源OSphp.COM.CN
$contents = file_get_contents($f);
if ( strpos($contents, $this->search_phrase) !== false )
$this->foundFiles [] = $f;
//開源代碼OSphp.COm.CN

}
}
return $this->foundFiles;
}
function GetDirContents($dir){
if (!is_dir($dir)){die ("Function GetDirContents: Problem reading : $dir!");}
if ($root=@opendir($dir)){
//php開源代碼

while ($file=readdir($root)){
if($file=="." || $file==".."){continue;}
if(is_dir($dir."/".$file)){

$files=array_merge($files,$this->GetDirContents($dir."/".$file));
}else{
$files[]=$dir."/".$file; //開源OSphp.COM.CN
}
}
}
return $files;
}
}
//Example :
$search = new searchFileContents;
$search->search('E:/htdocs/AccessClass', 'class'); //開源代碼OSphp.COM.Cn
var_dump($search->foundFiles);
?>

php技術Search File Contents PHP 搜索目錄文本內(nèi)容的代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 东兴市| 隆化县| 阿城市| 铜鼓县| 沭阳县| 普格县| 积石山| 峨边| 黔西县| 汤原县| 分宜县| 普陀区| 奉化市| 富裕县| 丰都县| 同江市| 海丰县| 高碑店市| 鞍山市| 灵川县| 安庆市| 嘉荫县| 潢川县| 会泽县| 逊克县| 科技| 赣州市| 鄂托克前旗| 比如县| 平乡县| 太仆寺旗| 姜堰市| 太湖县| 临沧市| 东阿县| 大宁县| 堆龙德庆县| 芜湖市| 固始县| 平远县| 阿坝县|