Re: strpos

From: Date: Fri, 16 Nov 2001 14:54:14 +0000
Subject: Re: strpos
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-74871@lists.php.net to get a copy of this message
I always get strpos wrong. So typically in this case I would do something like: list($file,$ext) = explode('.',$yourimage); if ($ext != 'jpg' or $ext != 'jpeg') { error... } (More properly we should make sure jpg or jpeg are at the very end of the filename i.e. you probably don't like myfile.jpegold.gif so you would need: list($ext,$file) = explode('.',strrev($yourimage)); $ext = strrev($ext); $file = strrev($file); if ($ext != 'jpg .....etc. ) If $yourimage really is a reference to an image e.g. an uploaded image, you might like to run getimagesize() on it to see if it really, really is a jpeg and not just called .jpg or .jpeg see (http://www.php.net/manual/en/function.getimagesize.php). George Jtjohnston wrote: > > I suppose I'm doing this right? I want to know if the user entered > "\.jpeg" or "\.jpg". If he didn't, it should error. > > It errors anyways? What do I have to do add slashes in my <input>??? > :o) > > // if((!strpos($yourimage, "\.jpg")) || (!strpos($yourimage, > "\.jpeg"))) \\ <--- tried both! > if((!strpos($yourimage, ".jpg")) || (!strpos($yourimage, ".jpeg"))) > { > error_found("error found"); > $errorfound++; > }

« previous php.general (#74871) next »