www.webdeveloper.com
Results 1 to 3 of 3

Thread: help with sort links script

  1. #1
    Join Date
    Dec 2006
    Posts
    2

    help with sort links script

    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);
    }
    ?>

  2. #2
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    *yawn*
    PHP Code:
    <?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";
    }
    ?>

  3. #3
    Join Date
    Dec 2006
    Posts
    2
    Thanks alot man, worked perfectly

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles