views:

76

answers:

3

I can't seem to figure out why the following code doesn't produce a new line in my text file - neither does using \n etc either - any ideas what could be wrong?

    $data = $name . ' | ' . $_POST['comment'] . PHP_EOL;

    //write to file
    $f = file_put_contents('posts.txt', $data, FILE_APPEND);
+1  A: 

Are you viewing the text file in an internet browser by any chance?

If you are, the browser will get rid of the newline characters (unless you're using PRE tags).

Michel Carroll
Aha, that was it - thanks Michel!
steve-o
A: 

Have you tried \r or \n\r ? Just an idea.

kalkin
A: 

Try double quotes: $data = $name . ' | ' . $_POST['comment'] . "\n";
Or: $data = "$name | {$_POST['comment']}\n";

Alec