Jump to content

Archived

This topic is now archived and is closed to further replies.

stevepatd

Funny Line Feeds

Recommended Posts

I have a php file that outputs text to a standard ASCII text file.  I put a \n at the end of each line as it writes out.  I then have another php file that reads these generated files and does something with the data.  The problem is, when the second file reads the generated data it doesn't like the \n.  When I edit the generated files with Notepad instead of seeing a carriage return/line feed making the data line up in nice neat columns, I see a little square in place of the \n and the text continues on the same line wrapping at the edge of the screen.

WHat command should I be using to prevent this?

I'm running on a Windows server, either Win2000 or 2003.

Thx,
Steve

Share this post


Link to post
Share on other sites
It is because Windows uses a carriage return and then a line feed (\r\n) - CRLF.
Linux uses a line feed (\n) - LF.
Macintosh uses a carriage return (\r) - CR.

Share this post


Link to post
Share on other sites
If the file is being created in unix and read in windows, you can probably fix it by using \r\n for linefeed instead of \n.  If it's some other combination, the solution will be different.  nl2br() is for displaying in html, so it doesn't help here.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.