Making new line in php write to file

Ghostff picture Ghostff · Oct 12, 2014 · Viewed 7.5k times · Source

I tried this but wont work

<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "Mickey Mouse\n";
fwrite($myfile, $txt);
$txt = "Minnie Mouse\n";
fwrite($myfile, $txt);
fclose($myfile);
?> 

This is how it displays in my newfile.txt:

Mickey MouseMinnie Mouse`

but I want it like this:

Mickey Mouse
Minnie Mouse

Answer

Marcus Rommel picture Marcus Rommel · Oct 12, 2014

It is the best to use PHP_EOL. It's cross-platform and will automatically choose the correct newline character(s) for the platform PHP is running on.

$txt = "Goofy".PHP_EOL;