Re: read last three letters

From: Date: Wed, 29 May 2002 01:22:05 +0000
Subject: Re: read last three letters
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-99605@lists.php.net to get a copy of this message
or, try this: <? $c = "143"; if(file_exists('{$c}.gif')) { echo '<img src="{$c}.gif">'; } elseif(file_exists('{$c}.jpg')) { echo '<img src="{$c}.jpg">'; } else { echo '<img src="oooops.gif">'; } ?> Justin French -------------------- Creative Director http://Indent.com.au -------------------- on 29/05/02 7:56 PM, r (r@jumac.com) wrote: > Hi PHP ppl, > > I have a directory named cartoons, > it has around 180 files in them ONLY images, > the filenames are 1.jpg, 2.jpg......5.gif, 6.gif etc etc > if you got confused with the above line its basically all the files are > numbered from 1-180 and the file types are mixed JPG and > GIF. > > I have a program that displays each of the cartoons displays a <-- Prev * > * * Next--> link, basicaly theres a hidden field that specifies the current > number and if you click prev its c=c-1 and if your press next its c=c+1, but > I have no idea if the next cartoon is either JPG or GIF and so am displaying > both like so in my code: > > <img src=$c.gif> > <img src=$c.jpg> > since only one is valid the other shows an ugly blank image placeholder > graphic. > > Any idea on how i can read the last three letters of the file to determine > if its gif/jpg? > > Kindly reply, > -Ryan. >

« previous php.general (#99605) next »