note 122013 added to function.array-filter
| From: | bimal at sanjaal dot com | Date: | Tue, 12 Dec 2017 11:29:26 +0000 |
| Subject: | note 122013 added to function.array-filter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209355@lists.php.net to get a copy of this message | ||
I needed to filter specific files. glob was a good option but had issues being case sensitive. And
at the same time, I had to filter the directory names like ".", "..",
".git", etc which could be complex.
I used a snippet as below, where I could implement this complex filter. Just modify your method:
image_file.
<?php
class handlers
{
private $path;
public function __construct($path)
{
$this->path = realpath($path);
}
public function image_file($file="abc.png")
{
$is_image_file = is_file($this->path."/".$file);
return $is_image_file;
}
}
$path = realpath("../../gallery-200x400");
$files = scandir($path);
print_r($files);
$files = array_filter($files, array(new handlers($path), "image_file"),
ARRAY_FILTER_USE_BOTH);
print_r($files);
?>
----
Server IP: 208.43.231.9
Probable Submitter: 104.205.115.227
----
Manual Page -- http://php.net/manual/en/function.array-filter.php
Edit -- https://master.php.net/note/edit/122013
Del: integrated -- https://master.php.net/note/delete/122013/integrated
Del: useless -- https://master.php.net/note/delete/122013/useless
Del: bad code -- https://master.php.net/note/delete/122013/bad+code
Del: spam -- https://master.php.net/note/delete/122013/spam
Del: non-english -- https://master.php.net/note/delete/122013/non-english
Del: in docs -- https://master.php.net/note/delete/122013/in+docs
Del: other reasons-- https://master.php.net/note/delete/122013
Reject -- https://master.php.net/note/reject/122013
Search -- https://master.php.net/manage/user-notes.php