On 8 Sep 2012, at 15:35, David McGlone <david@xxxxxxxxxxxxx> wrote: > I have a function that reads a directory and gets all the file names of images, > and I am wondering if it's possible to concatinate this function withint an > image tag. Here's an example I tried. > > function pictures() { > > $dir = 'images/property_pics/'; > $file = array(); > if(is_dir($dir)){ > if($open = opendir($dir)){ > > while (($file = readdir($open)) !== false && $file !== ".") { > > $names = substr($file, 9, 20); > echo $names; > > } > > } > closedir($handle); > } > } > > $rs = $pager->paginate(); > if(!$rs) die(mysql_error()); > while($row = mysql_fetch_assoc($rs)) { > > > echo "<div id='record'>"; > echo "<span>"; > echo <im src = "images/$row[$MSL_No]pictures();"> > > What I am trying to do is get the last part of an image name, because I know > the $MSL_No is always a 9 character name which matches the image name in > but in the database, the last bit of characters are not there so I'm trying to > take the last characters of the image name and concatinate them to each > image name.. > > Wow this is harder to explain that I thought. Here's an example > > In the DB I have a row MSL_No and the contents is: 123456789 > > In my images folder I have an image named 123456789_R13_1.jpg > > My goal: get the MSL_No out of the DB and concatenate anything after it so I > would end up with the whole image name.. > > I hope this all made sense. :-/ 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']).'" />'; ?> If you need to extract more than one image filename you should be able to modify that pretty easily. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php