Location: PHPKode > scripts > Alphabetize line > Alphabetize-Line.php
<?php
	$fh = fopen("XXX", 'r');
	$i = 0;
	flock($fh, LOCK_SH);
	while (!feof($fh)) {
			$data = fgets($fh, 500);
		$array[$i] = $data;
		$i++;
	}
	flock($fh, LOCK_UN);
	fclose($fh);
		
	sort($array);
	$count = count($array);
		
	$gamelist = fopen("XXX", 'w');
	flock($gamelist, LOCK_EX);
	for($i = 0; $i <= $count; $i++) {
		fwrite($fh, $array[$i]);
	}
	flock($fh, LOCK_UN);
	fclose($fh);
?>
Return current item: Alphabetize line