Click to See Complete Forum and Search --> : help with sort links script


UsHi3735
12-02-2006, 07:20 PM
I needed a script to create a links page for about 500 songs I had in a folder automatically. It looks like this http://dadeebaker.com/music.shtml
the problem is I need to modify the code to alphabetize that because right now its completely scrambled, I'm terrible with php, so can someone help me out with this. Thanks

I used this code (music1 is the folder the music is in btw)
<?php
$dir = "music1";
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$name = str_replace(".mp3", "", $file);
echo '<a href="'. $dir .'/'. $file .'">'. $name .'</a><br />';
}
}
closedir($handle);
}
?>

ShrineDesigns
12-02-2006, 08:45 PM
*yawn*<?php
$dir = 'music1/';
$list = array();

if(($handle = @opendir($dir)) != false)
{
while(($file = @readdir($handle)) !== false)
{
if(preg_match("/\.mp3$/i", $file))
{
$list[] = $file;
}
}
@closedir($handle);
}
natsort($list);

while(list(, $song) = each($list))
{
echo "<a href=\"$dir$song\">" .preg_replace("/\.mp3/i", '', $song). "</a><br />\n";
}
?>

UsHi3735
12-03-2006, 09:00 AM
Thanks alot man, worked perfectly