hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Problem reading/sorting a directory (PHP)
Reply

Forum Jump

Problem reading/sorting a directory (PHP)

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 06-26-2004, 11:45 PM
ProdigySim ProdigySim is offline
Newbie
 
Join Date: Apr 2004
Posts: 7

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



Sponsored Links
  #2  
Old 06-27-2004, 12:18 AM
nexcess.net nexcess.net is offline
Junior Guru
 
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!

Reply

Related posts from TheWhir.com
Title Type Date Posted
Microsoft Apologizes, Details Online Services Outage Web Hosting News 2014-06-30 10:29:39
Ads Available for the Second Printing of WHIR’s Annual Hottest Hosts Directory Blog 2014-04-08 16:52:36
Hostway Corporation Listing 2014-01-14 22:41:27
Newtek Web Hosting Listing 2014-01-08 18:51:25
EIG Revenues: Higher than Reported Blog 2013-09-18 12:15:49


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?