Page 1 of 1

Problems writing newline to txt file

PostPosted: 09. October 2014 11:21
by TgaWookie
I am trying to write data to a text file using php. After each line I am adding "\r\n" to the end of it, but when I open the file it only contains the "\n" at the end of the line so windows notepad shows all data on just one line. I have run the exact same files on USBWebserver and it works fine. Why is XAMPP changing the end of line characters? and how do I stop it happening?

Re: Problems writing newline to txt file

PostPosted: 09. October 2014 12:04
by JJ_Tagy
First, I recommend dumping windows notepad and go for something like Notepad++. Then you will see that XAMPP does not change anything as you can turn on the formatting view.

I have no issues getting this to work. Perhaps you should share your code.

Code: Select all
<?php
  $file = fopen("test.txt", "w");
  echo fwrite($file, "Hello World. Testing!\r\n");
  echo fwrite($file, "This is line two.");
  fclose($file);
?>


Output:
Code: Select all
Hello World. Testing!
This is line two.