I tried looking in the PHP docs but there are 50,000 String functions; how can I find out if a string ends with .gif, .png, .jpg, .bmp, or .jpg?
Printable View
I tried looking in the PHP docs but there are 50,000 String functions; how can I find out if a string ends with .gif, .png, .jpg, .bmp, or .jpg?
PHP Code:// output array
$elements = count($dirs);
for ($i = 0; $i<$elements; $i++) {
if (eregi("gif$|png$|jpg$|bmp$|jpg$|jpeg$", $dirs[$i])) {
echo "<font color=\"#ff0000\">$dirs[$i] - Image File!</font><br>";
} else {
echo "$dirs[$i] - Not an image File<br>";
}
}
$ext = substr ("myfile.gif", -3);
$ext will be "gif"
Chris's way worked. I would've replied but I broke my Internet connection :(