Forum Moderators: coopster

Message Too Old, No Replies

Random Newline Problem

         

Sonnenblume

10:44 am on Jan 18, 2008 (gmt 0)

10+ Year Member



I'm having difficulty with a really simple script (which makes it all the more annoying to have to ask).

<?
$text="here is line 1 \n here is line 2 \n here is line 3 \n";
$file = "test.txt";
$temp = fopen($file, "w");
fputs($temp,stripslashes($text));
fclose($temp);
?

Essentially its a really simple script which just writes 3 sentences, each on a new line. The problem im having is that when I open up my txt document everything is appearing on 1 line instead of 3, with the newline character appearing as a small square. Any suggestions?

venelin13

11:18 am on Jan 18, 2008 (gmt 0)

10+ Year Member



I've just tested your code and it works for me. The problem is probably related to the character set of the editor you are using.

Also, if you are on Windows, use \r\n instead of \n - give it a try, this may helps you.

adwatson

4:13 pm on Jan 18, 2008 (gmt 0)

10+ Year Member



Try looking at the output file in a different text editor - if you're using notepad, it'll display some newline chars as a square. Try textpad or some other more full-featured text editor.