contents Search File Contents PHP 搜尋目錄文字內容的程式碼
這個類別可以用來搜尋在給定的文字目錄中的檔案。
它可以給定目錄遍歷遞歸查找某些檔案副檔名的檔案。
並開啟找到的文件,並檢查他們是否包含搜尋字詞。
它傳回一個含有所有檔案的清單包含搜尋字詞陣列。
複製程式碼 程式碼如下:
/*
Class for searching the contents of alling 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){
function search($directory, $search_phrase){
$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->foundFiless$ [] = $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;
}
}
return $files;
}
}
return $files;
}
}
}
}return $files;
} } return $files; } } return $files; } } return $files; } } return $files; } ) >} //Example : $search = new searchFileContents; $search->search('E:/htdocs/AccessClass', 'class'); //開源程式碼OSPHP.COM.Cn var_dump($search->foundFiles); ?> 以上就介紹了contents Search File Contents PHP 搜尋目錄文字內容的程式碼,包括了contents方面的內容,希望對PHP教學有興趣的朋友有幫助。
熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)