andy182 Posted October 4, 2008 Share Posted October 4, 2008 I have made the following code to list the files in a directory, but wondering if there's any chance you could help me and explain how to list them in alphabetical order. <?php $path = "tabs/"; $dir = opendir($path); echo "<ul>\n"; while($file = readdir($dir)) { if ($file != "." && $file != ".." && $file != ".php") { list ($name, $ext) = explode (".", $file); echo "<li><a href = \"" .$path.$file. "\" target = \" _blank\"> ".$name." </a></li> \n"; } } echo "</ul>\n"; closedir($dir) ?> Quote Link to comment Share on other sites More sharing options...
zq29 Posted October 4, 2008 Share Posted October 4, 2008 You could add them to an array while looping then sort the array with sort(), alternatively, you could use glob() to fetch the directory contents - It lists them alphabetically be default, I believe. Quote Link to comment Share on other sites More sharing options...
andy182 Posted October 4, 2008 Author Share Posted October 4, 2008 Thanks for your help, looping them in a array did the trick. Quote Link to comment 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.