I wouldn't know under what keyword to look for this in the PHP database, so I'm asking here.
Reason I want to know is because of how different Operating Systems handle new lines in textdocuments.
I'm using a CSV file in windows but each time I think I add a new line, what really happens is the new line gets pasted to the back of the latest line.
Reason is, in windows, a new line is this: \r\n
And the CSVHandler.class.php file I'm using only adds \n
However, in MAC OS X that's the new line, which is different from windows.
So I'm looking for this so I can implement a simple if()
statement and solve this. Currently I've hardcoded the \r\n
, but it should be simpler, no?
PHP has included the constant PHP_EOL for solving the problem you face, available since php 4.3.10 and PHP 5.0.2 - it contains a suitable end-of-line sequence for the server that PHP is running on.
If you want to use a different end-of-line sequence suitable for a particular client, then you'll have to code that yourself. One way to determine the client OS is to use get_browser, assuming your server has an up-to-date browscap.ini
You could use the predefined constant PHP_OS.
I'm using
if (PHP_OS === 'WINNT') {...}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With