Hi; A while back you fine folks helped me understand how to create an array of (image) filenames by filtering on the EXTENSIONS.
Now I want to filter based on the beginning of the filenames (say I've got a bunch of .jpgs in a directory with names like "unknown01.jpg, unknown02.jpg, unknown01.jpg, etc. etc." along with other files with various other names.
Is there a simple mod to this code that will just pull the ones that start with "unknown" ?
function directory($dir,$filters)
{
$handle=opendir($dir);
$files=array();
if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}}
if ($filters != "all")
{
$filters=explode(",",$filters);
while (($file = readdir($handle))!==false)
{
for ($f=0;$f<sizeof($filters);$f++):
$system=explode(".",$file);
if ($system[1] == $filters[$f]){$files[] = $file;}
endfor;
}
}
closedir($handle);
return $files;
}
$filenames = directory (".","jpg,gif,png,bmp,JPG,GIF,PNG,BMP"); //call the function
Thanks.