tags:

views:

99

answers:

2

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);
A: 

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

stillstanding
Yes, in notepad.. Ok, so this is my problem then? Is there something that I can do to see the breaks in notepad?
jim
\r\n instead of \n
VolkerK
i use notepad2. download at www.flos-freeware.ch
stillstanding
Volker, thanks. Also to you RockJock. That did the trick. I was doing \n\r which I guess makes a difference.
jim
Thanks rockjock. going there now.
jim
+2  A: 

try

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

or

$file = 'test.txt';
$message = "test\r\n";
file_put_contents($file, $message, FILE_APPEND);
mathroc
+1 for using `PHP_EOL`
Gordon