php fwrite to new line

+2 LP new · November 21, 2014
write($handle, $name."\n"); 
does not write to new line. Anything wrong with it, suggestion....

Post a Reply

Replies

Oldest  Newest  Rating
0 Ron Butcher · November 22, 2014
What editor are you using to open the file?  

Notepad that comes with Windows does not recognize any newline command except for CR, and LF.

Open the file with Notepad++ or another editor and it will probably work fine.
0 Chris Whitlock · November 22, 2014
Kind of what @RonButcher mentioned. You need to check the file type that you are writing too. Such as if you're writing to a normal .txt file then yes, it should work with '\n' but if you're doing it with another file type like trying to echo or print like that than no. Such as writing to a .CSV file won't see \n as a newline.

If you have to use whatever file type you are using then you can probably look online and see what they use to make a new line. Like in a html output or file it'll be '<br>'.


Best regards,
Chris W.
0 LP new · November 26, 2014
I am using notepad++, writing into .txt file in an php program. Still does not work with '\n' or "\n" within otherwise quotes.
0 Chris Whitlock · November 28, 2014
Sorry about the delayed response, LP new.

Okay, great. I use notepad++ has my primary program. Check and make sure in the settings it is saving the .txt file in a Windows UTF-8 without BOM format. I have mine set as Unix UTF-8 because I use it restrictly on linux servers.

You change that setting in Settings > Preferences > New Document
And adjust it to Windows in UTF-8 with-out BOM. I know that file format supports \n as I have done it that way before. If your still having problems I'll type a demo up and share it.


Best regards,
Chris W.
  • 1

PHP

107,116 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators