I am working on php script that takes an input (using html) stores those values in a separate text file. I managed to get that to work. But the thing is I wanted to be able to sort those values alphabetically. Since their are an unspecified amount of inputs I tried using an explode on my output in order to store those values as an array so that I can sort them. Problem is explode makes each input its own separate array instead of one whole array. I figure some type of loop is needed to fix that but I can't figure out how to go about creating it [i'm pretty new to php]. Any advice? Heres my code for my PHP script:
$filename = "ip_collection.txt";
$fileHandle = fopen('ip_collection.txt', 'a+') OR die("can't open file\n");
$ip = $_SERVER['REMOTE_ADDR'];
$name = stripslashes($_POST['lastName'] . ", " . $_POST['firstName']);
$textFromForm = $name. " | " . $ip;
$newtext = $textFromFile . $textFromForm;
$output = explode("\n",$newtext);
sort($output);
foreach($output as $key => $value) {
fwrite($fileHandle, $value."\n");
}
fclose($fileHandle);