anf.etienne Posted March 11, 2009 Share Posted March 11, 2009 Hi, i have a code that reads a directory and puts all the images within the directory into table format with links underneath. In my directories I have images that are named 1.jpg 2.jpg 3.jpg etc and i have images that are named 1b.jpg 2b.jpg 3b.jpg how can i change this code so that all the images with b.jpg is not included when the code is run to view images within a directory? <?php $r = 0; for($n=0; $n<$total_items; $n++) { if($n !=0 && fmod($n, 5) == 0) { echo "</tr><tr>"; } $imageL= $path.$item[$n]; $img_path="http://ve-creative.com/test/8/$imageL"; // display the item echo '<td><center><p><a href="'.$img_path .'"><img src= "'.$path.$item[$n] .'" height="100" width="100"></a></p></center>'; echo "<center><p><a href=imgEdit.php?img=$img_path> > Edit Image < </a></p></center><br></td>"; } if($r>0) { for($m=$r; $m<5; $m++) { echo "<td> </td>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148915-solved-exclude-certain-files/ Share on other sites More sharing options...
kickstart Posted March 11, 2009 Share Posted March 11, 2009 Hi Just check the end of the string containing the file name. <?php $r = 0; for($n=0; $n<$total_items; $n++) { if($n !=0 && fmod($n, 5) == 0) { echo "</tr><tr>"; } $imageL= $path.$item[$n]; if (substr($imageL,-5) != 'b.jpg') { $img_path="http://ve-creative.com/test/8/$imageL"; // display the item echo '<td><center><p><a href="'.$img_path .'"><img src= "'.$path.$item[$n] .'" height="100" width="100"></a></p></center>'; echo "<center><p><a href=imgEdit.php?img=$img_path> > Edit Image < </a></p></center><br></td>"; } } if($r>0) { for($m=$r; $m<5; $m++) { echo "<td> </td>"; } } ?> If there were several different varieties you wanted to avoid displaying then a regular expression check might be better. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/148915-solved-exclude-certain-files/#findComment-781930 Share on other sites More sharing options...
anf.etienne Posted March 11, 2009 Author Share Posted March 11, 2009 Thanks Keith......it works perfectly Quote Link to comment https://forums.phpfreaks.com/topic/148915-solved-exclude-certain-files/#findComment-781940 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.