Re: File Searching problem
| From: | Burhan Khalid | Date: | Tue, 01 Apr 2003 23:25:32 +0000 |
| Subject: | Re: File Searching problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-141894@lists.php.net to get a copy of this message | ||
Poon, Kelvin (Infomart) wrote:
[ snip ]
My problem is I don't know how to open all of the files in the directory, since I don't know the name of the files. These php files keep updating, and the names would be KB_XXXXXX.php, where XXXXXX is the ID of that particular file. I need to open ALL of these files and search the phrase in
it. Any body have any idea how I can open these files? I am probably going
to be using RE to search, so maybe I can use fread() to store a file in a variable and search one file at a time.This little function will return all the files in a directory as an array. Hope this helps : function getFiles($dirname) {
$handle=opendir($dirname);
while ($file = readdir($handle))
{
if($file=='.'||$file=='..')
continue;
else
$result_array[]=$file;
}
closedir($handle);
return $result_array;
}
Call it like this : $file_list = getFiles("/parent/sub");
Regards,
--
Burhan Khalid
phplist[at]meidomus[dot]com