Jump to content

natcasesort works on one server but not on another


Viola

Recommended Posts

Hi

 

I have a problem that I was hoping that someone can help me with.

 

I'm trying to use natcasesort() to sort an array.  This works fine on my laptop (which I use for testing and which uses php 5.2.6), but doesn't work at all on the server that hosts my website (it's just displayed unsorted; uses php 5.2.4).  Both machines run apache.

 

I figure that as it works fine in one place, but not in the other, it is likely that the problem is in the difference between the configurations of these two php installations.

 

Please can you tell me if you have any idea of what could be causing this?

 

In case it helps shed some light, here's my code (in brief):

 

        $arr= array();
$arr = ListFilesInFolder( CLIENT_DIR . "/" . $folder . "/" );
$sorted = natcasesort($arr);	
        

 

Thanks for your consideration.

 

Viola

Link to comment
Share on other sites

It would really help if you posted your code that is displaying the results and post an example of some values that don't work as expected.

 

It is fairly likely that on the system where your code appears to work that the files are already in the order you expect and your code is not actually doing what you think it is.

Link to comment
Share on other sites

Hi

 

Thanks for both your responses -- gave me "food for thought".

 

PFMaBiSmAd -- I thought that you could be right, so I uncommented the natcasesort from my code.  The result was that it made no difference to the order that the array was shown in.  My local version was still in alphabetical order, and my remote version was not.  There must be something, somewhere on my local machine that is sorting the files.  I think that this may be external to my code (see below) because

  • there aren't any sort functions in my code
  • the code on both machines (local & remote) is the same

 

severndigital -- thanks for the link.  I found that although natcasesort() didn't work on my remote machine, sort() did work, so I implemented the ignorecasesort() function that was posted by "Ulli at Stemmeler dot net" at the bottom of that page.

 

It's still a bit of a mystery to me as to:

  • why the files on my local machine are sorted, even when I'm not using a sort function
  • why natcasesort doesn't seem to work on my remote machine

 

But at least I've done the job at hand.

 

Thanks for your help.

 

Viola

 

 

/*
    Return a list of files in a given folder
    Returns an array of filename strings, or false if there are no files in the folder.
    The filenames will NOT contain path info.
*/
function ListFilesInFolder($path)
{
    $result = false;

    $dir = dir($path);
    $dir->rewind();
    while ($file = $dir->read()) {
        if (is_file($path . $file)) {
            $result[] = $file;
        }
    }
    $dir->close();
   
    return $result;
} 



/* 
    Return an array of TSupportFile objects for each file in a given client folder.
    The filenames will not contain path info.
*/
function ListFilesInClientFolder( $folder ) 
{
$s = ListFilesInFolder( CLIENT_DIR . "/" . $folder . "/" );
//      natcasesort($s);
$count	= count( $s );
$result	= array();
for ($i=0; $i < $count; $i++) {
	$result[] = new TSupportFile( $s[$i], $folder );
}

return $result;
} 



/*
    Gets a list of files in a directory and displays them in a web page 
*/
function MakeDownloadList( $foldername ) {
$files = ListFilesInClientFolder( $foldername );

/* The rest of this function is just outputting html that displays each file's details in turn.  I cannot see any calls to any sort functions in here or in any sub-fuctions that are in here. */
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.