smordue Posted December 21, 2009 Share Posted December 21, 2009 I am trying to create a customized <ul> from a list of files in a directory. I need the final result to be: <li><img src="img/Fall in Germany.jpg" title="Fall in Germany" alt="Fall in Germany"/></li> Here is where I am so far: <?php if ($handle = opendir('img')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $thelist .= '<li><img src="img/'.$file.'" title="'.$file.'" alt="'.$file.'"/></li>'; } } closedir($handle); } ?> <ul class="gallery"> <?=$thelist?> </ul> What I need to be able to do is strip off the file extension for the title and alt tags only. Link to comment https://forums.phpfreaks.com/topic/185902-custom-list-from-directory/ Share on other sites More sharing options...
ChemicalBliss Posted December 21, 2009 Share Posted December 21, 2009 Save the $file variable as another variable, and use either Explode() or substr() (see the php manual for more info on how to use these functions). Then for the Title and Alt parts use the new variable instead. -CB- Link to comment https://forums.phpfreaks.com/topic/185902-custom-list-from-directory/#findComment-981708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.