Jump to content
Larry Ullman's Book Forums

Recommended Posts

Chapter 11, pg. 293 includes the following text:

 

 

"When appending data to a file, you normally want each piece of data to be written on its own line, so each submission should conclude with the appropriate line break for the operating system of the computer running PHP. This would be

 

■ \n on Unix and Mac OS X

■ \r\n on Windows"

 

I'm pretty sure this is the first time the distinction between \n for Unix/Max and \r\n for Windows is mentioned in this book.

 

Does this mean that \n wouldn't work on a Windows-based server?

 

Could someone please elaborate on this?

Link to post
Share on other sites

Good question. So those characters are how the different platforms indicate the end of a line. If you used the wrong character for your system, then it "wouldn't work" in the sense of the system couldn't read in the file in such a way as to recognize each line. In other words, if you used \n on Windows, and opened the file in Notepad, it'd all run together as if it were on one line. More importantly, if you used PHP's file() function to read in the file to an array, it would be read in as one line.

 

If you might switch servers, you can instead use the PHP_EOL constant, which represents the correct value for the current OS (the server OS).

  • Upvote 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...