Link to home
Start Free TrialLog in
Avatar of mar2195
mar2195

asked on

PHP Flatfile Sorting Causing A Warning

I've used this code before without any issues.  I must be overlooking something here...  hoping that a few more eyes can help me see what I'm doing wrong.  (Hosting is using PHP Version 4.4.9)

Here is the warning that I'm getting:
Warning: natcasesort() [
function.natcasesort
]: The argument should be an array


I have tried using:
natcasesort($file)
natcasesort($lines)
RESULT:  Same warning.

FYI: This WARNING displays at each items' display.  (Yes, the data is still creating the flatfile output unsorted.)

<?php

/* SAMPLE RECORDS FROM FLATFILE:
Zees|Alan Zees, Ph.D.|http://www.alanzees.com|end_record
Aarons|Ben Aarons, M.F.T.|http://www.benaarons.com|end_record
*/

$file = fopen("includes/related_sites_data.txt", "r");
	if (!$file) { echo 'ERROR: Unable to open file: <strong>'.$file.'</strong>'; }

while (!feof($file) ) {
	$lines = fgets($file);

	natcasesort($file);

	$ele = explode('|', $lines);

	if($ele[0]){
		$db_sort_name = $ele[0];
		$db_display_name = $ele[1];
		$db_site = $ele[2];
		$db_end_record = $ele[3];
	
		$db_end_record = substr_replace($db_end_record,"",-1); // trim last char
?>

					<li><a href="<?php echo $db_site;?>" target="_blank" title="<?php echo $db_display_name;?>"><?php echo $db_display_name;?></a></li>

<?php

	}
}
fclose($file);

?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hosting is using PHP Version 4.4.9
This puts you about a decade or more behind the times.  Consider upgrading -- you would not want to be driving a car that old -- it's unsafe.

When you do not know what kind of data your PHP script is using, you can (and should) find out with var_dump().
Avatar of mar2195
mar2195

ASKER

1.  Gary:  "split lines into a multi dimensional array and then sort the array"  Yep.  That worked.  Thanks.

2.  Ray:  Unfortunately, I do not have control of the installs (ie:  PHP version) on this server.  Of course, I would have advised a PHP upgrade.  I can only imagine the other issues going on with old 'everything'.