What pattern should I use for glob function to filter only folders that contain numeric string.
this will show only folders with a single digit:
glob('/path/to/files/[0-9]')
What about folders with multiple digits or when is_numeric is true?
What pattern should I use for glob function to filter only folders that contain numeric string.
this will show only folders with a single digit:
glob('/path/to/files/[0-9]')
What about folders with multiple digits or when is_numeric is true?
function filterFiles($path, $flag="", $ext="", $regex_pattern="") {
if ($ext) $ext=".$ext";
if ($flag=="files") $files=array_filter(glob("$path/*$ext"), "is_file");
else if ($flag=="dirs") $files=array_filter(glob("$path/*$ext"), "is_dir");
else $files=glob("$path/*$ext");
if ($regex_pattern) foreach($files as $i=>$file) {
if(!preg_match($regex_pattern, basename($file))){
unset($files[$i]);
}
}
$result=array_values($files);
return $files;
}
$revPaths=filterFiles($path,"","","/^\d+$/");