You cannot place "strings" inside a character class. Character classes work with characters, not strings. A character class can match only one out of several characters.
So, the following regex:
/[\.gif$\.png$\.bmp$\.jpg$\.jpeg$]/
matches a single character from the character list between [
and ]
. Also, remember that the dot is not a metacharacter inside a character class, so you don't need \.
- just .
will suffice, but it doesn't matter anyway because this is a wrong approach.
Visual representation:
Use alteration to achieve what you want. For example, (foo|bar)
matches foo
or bar
. For your requirements, the following regular expression might work:
/\.(gif|png|bmp|jpe?g)$/
Although, I would not use a regex for this. There's already a function that was built for the exact purpose -- to determine the extension of a file (or URL):
$ext = pathinfo($url, PATHINFO_EXTENSION);