smordue Posted December 24, 2009 Share Posted December 24, 2009 What and where do I add to sort the output of this alphabetically? <?php if ($handle = opendir('img')) { while (false !== ($pics = readdir($handle))) { if ($pics != "." && $pics != "..") { $picfile_x = substr($pics, 0, -4); $piclist .= '<li><img src="img/'.$pics.'" title="'.$picfile_x.'" alt="'.$picfile_x.'"/></li>'; } } closedir($handle); } ?> Thanks! Steve Link to comment https://forums.phpfreaks.com/topic/186260-where-to-add-sort/ Share on other sites More sharing options...
oni-kun Posted December 24, 2009 Share Posted December 24, 2009 "$piclist .=" sort is an array function, You're outputting them as HTML in one string, you'll have to recode it to use sort() or work your own alphabetic sorting on the result. You can put them into an array beforehand, and echo " src=".imagepath[0]"/>" or similar sorted.. Link to comment https://forums.phpfreaks.com/topic/186260-where-to-add-sort/#findComment-983719 Share on other sites More sharing options...
PFMaBiSmAd Posted December 24, 2009 Share Posted December 24, 2009 Or you could use the glob function as that returns an array in alphabetical order by default. Link to comment https://forums.phpfreaks.com/topic/186260-where-to-add-sort/#findComment-983720 Share on other sites More sharing options...
smordue Posted December 24, 2009 Author Share Posted December 24, 2009 This is a part of a jquery photo gallery script, so I am not sure how much messing I can do to it without breaking the result. I just thought it would be nice if the photos displayed in order. Where might I add this glob() function? Link to comment https://forums.phpfreaks.com/topic/186260-where-to-add-sort/#findComment-983724 Share on other sites More sharing options...
PFMaBiSmAd Posted December 24, 2009 Share Posted December 24, 2009 <?php $files = glob('img/*.*'); $piclist = ''; foreach($files as $file){ $picfile_x = substr(basename($file), 0, -4); $piclist .= "<li><img src='$file' title='$picfile_x' alt='$picfile_x'/></li>\n"; } echo $piclist; ?> Link to comment https://forums.phpfreaks.com/topic/186260-where-to-add-sort/#findComment-983731 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.