Look at the readdir() function and you'll see how to list a directory. What you now need to do, instead of echo-ing the whole dir as you run through it, is to put the directory listing into an array. The next thing you'll do is to apply sort() to the array and then you should be getting alphabatized directory listing.
What you could also do is just ouputting (using for instinct passthru() ) the 'ls' command (if you're on a *nix machine). then you could just passthru 'ls -1' and get a dir listing in return.
regards,
thom