-2

I'm writing a webpage in php and part of my code is:

$files = scandir( '../www/media/' );
$fileTypes = [
  'pdf'   => 'text', 
  'jpg'   => 'text',
];

The problem is that if scandir finds a file that ends in "JPG", because of the case difference it won't be placed in $fileTypes. Is there a way to ignore the case difference so I don't have to type out the variations for lowercase and uppercase?

Kalmar
  • 195
  • 2
  • 18
  • 1
    http://php.net/manual/en/function.strtolower.php – j08691 Aug 08 '13 at 20:20
  • How is `$fileTypes` going to be used? If you're in control of that code, you could use `strtolower` (or `mb_strtolower`) when comparing. – lurker Aug 08 '13 at 20:20
  • where's the part of the code that actually involves the file name? – lsouza Aug 08 '13 at 20:20
  • Various options while processing: `strtolower()`, `stristr()`, or `/i` or [Can PHP's glob() be made to find files in a case insensitive manner?](http://stackoverflow.com/q/2520612) – mario Aug 08 '13 at 20:20

2 Answers2

0

Instead of ignoring case, why don't you just use strtolower() to convert your endings to lowercase. Keep in mind, on a unix server .jpg and .JPG are NOT the same.

Hydra IO
  • 1,537
  • 1
  • 13
  • 28
0

Have you try to strtolower the extensions of your file before insert it into your array?...

strtolower('JPG') == 'jpg'
Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97