Page 1 of 1

multiple extension filenames

Posted: Fri Mar 12, 2004 7:49 pm
by sh33p1985
in php
an image file could have the possible extensions .gif .jpg .jpeg, if im searching for a filename how can i make sure it has one of these extensions?

eg if im searching for the image src in a string containing all of the img tag parameters and the image could be one of these three extensions, how can i make sure it checks for all these variations?
thank you for any help

Posted: Fri Mar 12, 2004 7:53 pm
by Illusionist
uhm... maybe you could search for all of them??
Are you asking how to search through a string??

Posted: Fri Mar 12, 2004 7:57 pm
by sh33p1985
no no, in perl the follow link of code basically will list all .gif .jpg .jpeg

if($file =~ /.*\gif|jpe?g/){

need something similar in php

$image = "image"(then the possible extensions it could have here) to avoid doing multiple or statments

Posted: Fri Mar 12, 2004 8:14 pm
by angrytuna
if($file =~ /.*\gif|jpe?g/){
Not so good. What if my file is kathie_lee_gifford.png? Don't forget the $ to denote the end of the string when doing regexp searches like that.

That said, you might find the basename function useful, coupled with some creative application of scandir.

Posted: Sat Mar 13, 2004 6:30 am
by Pointybeard
You could use $array = explode(".", strtolower('FILENAME')) This will give you and array containg each bit of the filename broken up by '.' Then just get the last item in the array $ext = $array[count($array)-1]; Simple way to do it.