写入数组文本文件

So i want to write to a txt file using php. This txt file containts values for a array. The problem is that when i write in my textfield array[0] gets longer in stead of adding a new line in the array(array[1]). i tried and searched for 3 hours but cant find anything!

<html>
<body>
<form action="arraytest2.php">
  nieuwe regel <input type="text" method = "GET" name="nregel"><br>
  <input type="submit" value="Submit">
</form>


<?php


$file = "./members.txt";
$members = array();

if(isset($_GET['nregel']))
{
    $nregel = $_GET['nregel'];
    file_put_contents($file,$nregel,FILE_APPEND);


}

$members[] = file_get_contents($file);
var_dump($members);

?>
</body>
</html>

Try add ' ' before the string that you should save...

Something like:

file_put_contents($file, "
{$nregel}", FILE_APPEND);

And to read like array you'll need to split all file into array... Try something like:

preg_split('/
/', file_get_contents(...));

Remember... you have more then half path here...

edit the following line

file_put_contents($file,$nregel,FILE_APPEND);

to read

file_put_contents($file,$nregel."
",FILE_APPEND);

Write your value every time by appending any delimiter. Delimiter must not be the part of data.

Here I am taking '|' as delimiter

so code to write the file would be

file_put_contents($file, '|'.$nregel, FILE_APPEND);

and to retrieve

$members[] = explode('|', file_get_contents($file));