Search code examples
phpwindowsfileappendnewline

Append text with a newline in a Windows environment with file_put_contents()


I've got a file that I'm writing to and I cannot get file_put_contents() to append the next entry on a new line, even after a newline character. What am I missing? I'm on a Windows machine.

$file = 'test.txt';
$message = "test\n\n";
file_put_contents($file, $message, FILE_APPEND);

Solution

  • how are you viewing the contents of $file? if you're using notepad you can't see \n.