Dimitri Vorontzov Posted January 20, 2013 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? Link to comment Share on other sites More sharing options...
Larry Posted January 21, 2013 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 Link to comment Share on other sites More sharing options...
Dimitri Vorontzov Posted January 23, 2013 Author Share Posted January 23, 2013 Thank you for detailed explanation, Larry! Link to comment Share on other sites More sharing options...
HartleySan Posted January 23, 2013 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. Link to comment Share on other sites More sharing options...
Recommended Posts