I am trying to test if a url leads to an image, such as “http://i.imgur.com/vLsht.jpg”
by testing to see if the string contains “.jpg” or “.png” or “.gif” etc.
My curent code is:
if (stripos($row_rsjustpost['link'], ".png") !== false) {
//do stuff
}
I would like to do something like
if (stripos($row_rsjustpost['link'], ".png" || ".jpg" || ".gif") !== false) {
//do stuff
}
This is an okay use of a regular expression via
preg_match():Note: if the string must occur at the end like a file extension, terminate it with
$:If you were attempting to locate only one substring, it would be more appropriate to use
stripos(), but you can match a number of different patterns with a regex, without having to cough out a long if/else chain.