note 93547 added to function.opendir
| From: | jamon at clearsightdesign dot com | Date: | Tue, 15 Sep 2009 20:32:13 +0000 |
| Subject: | note 93547 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-160592@lists.php.net to get a copy of this message | ||
Another take on olivernasser's function below. I find this one slightly easier to understand.
<?php
// file_array() by Jamon Holmgren. Exclude files by putting them in the $exclude
// string separated by pipes. Returns an array with filenames as strings.
function file_array($path, $exclude = ".|..", $recursive = false) {
$path = rtrim($path, "/") . "/";
$folder_handle = opendir($path);
$exclude_array = explode("|", $exclude);
$result = array();
while(false !== ($filename = readdir($folder_handle))) {
if(!in_array(strtolower($filename), $exclude_array)) {
if(is_dir($path . $filename . "/")) {
if($recursive) $result[] = file_array($path, $exclude, true);
} else {
$result[] = $filename;
}
}
}
return $result;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 71.216.201.233
----
Manual Page -- http://www.php.net/manual/en/function.opendir.php
Edit -- https://master.php.net/note/edit/93547
Del: integrated -- https://master.php.net/note/delete/93547/integrated
Del: useless -- https://master.php.net/note/delete/93547/useless
Del: bad code -- https://master.php.net/note/delete/93547/bad+code
Del: spam -- https://master.php.net/note/delete/93547/spam
Del: non-english -- https://master.php.net/note/delete/93547/non-english
Del: in docs -- https://master.php.net/note/delete/93547/in+docs
Del: other reasons-- https://master.php.net/note/delete/93547
Reject -- https://master.php.net/note/reject/93547
Search -- https://master.php.net/manage/user-notes.php