I want to add a value (not overwrite!) to a txt file with
$fileUserId = fopen("fileUserId.txt", "w") or die("Unable to open file!");
$UserIdtxt = $UserID."||";
file_put_contents("fileUserId.txt", $UserIdtxt, FILE_APPEND);
fclose line and you are fine.
file_put_contents does this internally. And
fopen("fileUserId.txt", "w") clears the file.
'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.