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

Web ApplicationsPHP

Avatar of undefined
Last Comment
mar2195

8/22/2022 - Mon