Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sorting alphabetically

    PHP Code:
    <?
    $dir 
    "music/";
    unset(
    $param);
    if (
    is_dir($dir)) {
        if (
    $dh opendir($dir)) {
            while ((
    $file readdir($dh)) !== false) {
                if (
    $file != ".." && $file != "." && strstr($file,"mp3")) {
                    if (
    $param == "") {
                        
    $param "music/" rawurlencode($file);
                    } else {
                        
    $param .= "|" "music/" rawurlencode($file);
                    }
                }
            }
            
    closedir($dh);
        }
    }
    ?>
    What should I add to the script to make it sort the files alphabetically?

    Thanks in advance!

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Something like this asort(),
    bad thing is upper case will come before lower (i believe) IE A, B, C, a, c, e

    PHP Code:
        function GetDL($dir) {
            
    $dl = array();
            if (
    $hd opendir($dir)) {
                while (
    $sz readdir($hd)) {
                    if (
    preg_match("/^\.\.?$/",$sz) || is_dir($dir.$sz)) { continue; }
                    
    $dl[] = $sz;
                }
                
    closedir($hd);
            }
            
    asort($dl);
            return 
    $dl;
        } 
    Note: it is an array that is being sorted $dl

  • #4
    New Coder
    Join Date
    Sep 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    any one else?

  • #5
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    dude, what's wrong with sort from #2?

  • #6
    New Coder
    Join Date
    Sep 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php

    $fruits 
    = array("lemon""orange""banana""apple");
    sort($fruits);
    foreach (
    $fruits as $key => $val) {
        echo 
    "fruits[" $key "] = " $val "\n";
    }

    ?>
    what part should I include in array?


  •  

    Posting Permissions

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