PHP Sorting Question
Out of context: Reply #7
- Started
- Last post
- 11 Responses
- enobrev0
a regular sort will do the trick, but it is case sensitive. So if you have filenames that aren't all lower case, the sort won't be exact...
So you would need a sort function to surpass the case problem like:
function alphebetize ($a, $b) {
$sort_two[0] = strtoupper($a);
$sort_two[1] = strtoupper($b);
sort($sort_two);
return (strcmp (strtoupper ($sort_two[1]), strtoupper($b) ) ) ? 1 : -1;
}Then you set up your file array (pngs and jpgs only without the . and ..)
while ($file = readdir($handle))
if ($file != "." &&
$file != ".." &&
( ereg(".jpg",$file) ||
ereg(".png",$file) ) ) {$file_list[] = $file;
}
}and then use your alphabetize function:
usort($file_list, "alphebetize");
I have an example at http://photos.enobrev.com/
Let me know if you need the code.