Dimitri Vorontzov 0 Posted January 20, 2013 Report Share Posted January 20, 2013 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? Quote Link to post Share on other sites
Larry 428 Posted January 21, 2013 Report Share Posted January 21, 2013 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). 1 Quote Link to post Share on other sites
Dimitri Vorontzov 0 Posted January 23, 2013 Author Report Share Posted January 23, 2013 Thank you for detailed explanation, Larry! Quote Link to post Share on other sites
HartleySan 826 Posted January 23, 2013 Report Share Posted January 23, 2013 It's worth noting that in most decent text editors and IDEs these days, you can select the EOL (end-of-line) character(s) you want to use. Quote Link to post Share on other sites
Recommended Posts
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.