0

This question was asked by someone else 3 years ago (Can PHP's glob() be made to find files in a case insensitive manner?) , and I am still looking for a better solution using php script:

I am currently using:

$images = glob("" . $directory . "{*.jpg,*.gif,*.png,*.Jpg,*.Gif,*.Png,
*.JPg,*.GIf,*.PNg,*.JPG,*.GIF,*.PNG,*.jPG,*.gIF,*.pNG,*.jpG,*.giF,*.pnG}",
GLOB_BRACE);

to scan images file from a particular directory and just wondering if there is a simplier alternative. I tried:

$images = glob("" . $directory . "{/*.jpg,*.gif,*.png/i}";

and apparently it didn't work.

Or else, is there a replacement for sql_regcase()?

Thanks for teaching

Community
  • 1
  • 1
Michael Eugene Yuen
  • 2,470
  • 2
  • 17
  • 19

1 Answers1

0

Maybe this would work for you

$allowed = array("jgp","png", "gif");
$images = glob($directory, "*.*");
$images = array_filter($images, function($a) use ($allowed){
     $ext = substr($a, strrpos($a,"."));
     return in_array(strtolower($ext), $allowed");
});
Orangepill
  • 24,500
  • 3
  • 42
  • 63