How to actually convert a regular expression in the given code of the image handler so that when choosing a file with the extension .jPg, .pnG and so on, the function does not stop working and generally accepts the extension of the image without registering?

... if(preg_match('/[.](jpg)|(JPG)$/', $filename)) { $im = imagecreatefromjpeg($path_to_image_directory . $filename); } else if (preg_match('/[.](gif)|(GIF)$/', $filename)) { $im = imagecreatefromgif($path_to_image_directory . $filename); } else if (preg_match('/[.](png)|(PNG)$/', $filename)) { $im = imagecreatefrompng($path_to_image_directory . $filename); } ... 
  • 2
    Open the dock php.net/manual/ru/function.preg-match.php looking for (by Ctrl + F) the word register ... we see that after the closing / need to add the letter i total preg_match('/[.]jpg$/i', ...) - Mike
  • @Mike Oh, I'll check it out, but I think everything should work. Thank you) - Albert Ushakov

1 answer 1

Try for example like https://regex101.com/r/Pd8Log/3
That is specifically for jpeg

#.+\.jpe?g#is

hypha respectively

#.+\.gif#is

  • That is so? ... preg_match ('/.+ \. jpe? g / is', ...) - Albert Ushakov