PDA

Click to See Complete Forum and Search --> : What a string ends with


filburt1
Feb 17th, 2002, 02:04 PM
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?

chrisjk
Feb 17th, 2002, 02:24 PM
// 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>";
}
}

thinktank2
Feb 17th, 2002, 03:50 PM
$ext = substr ("myfile.gif", -3);

$ext will be "gif"

filburt1
Feb 17th, 2002, 05:34 PM
Chris's way worked. I would've replied but I broke my Internet connection :(