Results 1 to 2 of 2
  1. #1

    Problem reading/sorting a directory (PHP)

    PHP Code:
    <?
    if ($handle opendir('./favs')) {
            
    $number 0;
            while (
    false !== ($file readdir($handle))) {
                    if (
    $file != "." && $file != "..") {
                            
    $favsarray[$number] = $file;
                            
    $number++;
                    }
            }
            
    $favsarray natsort($favsarray);
            for(
    $i 0$i $number$i++) {
                    list(
    $fname$fext) = explode("."$favsarray[$i]);
                    if(
    $fname != 0) {
                            echo 
    "<a href=\"now.php?fav=$fname\">$fname</a> ";
                    } else {
                            echo 
    "<a href=\"now.php?fav=$fname\">$fname</a><br />";
                    }
            }
       
    closedir($handle);
    }
    ?>
    Apparently, $favsarray is blank, and $fname returns nothing, but, there is a 1.jpg in the ./favs directory.
    Can anyone tell me what's wrong?
    Edit/Delete Message

  2. #2
    Join Date
    Oct 2001
    Location
    Ann Arbor, MI U.S.A.
    Posts
    217
    http://php.net/natsort

    natsort doesn't return an array. You just use it like this:

    PHP Code:
    natsort($favsarray); 
    That should solve the blank array prob .

    Chris
    Chris Wells [clwells - at - nexcess.net]
    Nexcess - Beyond Hosting
    Dearborn, MI DC ● Southfield, MI DC
    Wordpress Hosting, Magento Hosting & More!

  3. Newsletters

    Subscribe Now & Get The WHT Quick Start Guide!

Posting Permissions

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