Re: a little trickery

From: Date: Sat, 08 Sep 2012 15:41:41 +0000
Subject: Re: a little trickery
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-319021@lists.php.net to get a copy of this message
On Sat, Sep 8, 2012 at 10:49 AM, Stuart Dallas <stuart@3ft9.com> wrote: > > Is there just one image in the folder that starts with the 9 digit number? In that case > it's dead simple (untested code): > > <?php > function completeImageFilename($prefix) > { > $matches = glob('images/property_pics/'.$prefix.'*'); > return $matches[0]; > } > > echo '<img > src="'.completeImageFilename($row['MSL_No']).'" />'; > ?> Stuart is, as usual, right on. Rather than do the filesystem handlers and loops, you should definitely consider glob(). Not only is it quicker, cleaner, and easier to use, but it's far less resource-intensive than your current implementation. -- </Daniel P. Brown> Network Infrastructure Manager http://www.php.net/

« previous php.general (#319021) next »