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?
You could use the predefined constant PHP_OS.
I'm using
Check the $_SERVER variable.
You can then use strstr (or any string comparison function) to check if you are on Windows. In this example, I checked the SERVER_SIGNATURE but you can use whatever key you want.
Lots of answers aleady, but here is my 2cents:
Also, try this function:
and in $b['platform'] will be OS.
BTW, *nix OS use \n as new line. Mac usees \r, Windows - \r\n
ARRRGH! PLEASE STOP PERPETUATING THIS MYTH!
Mac OS 9 used that like 10 years ago, but no one uses OS9 anymore. MACS USE UNIX LINE ENDINGS. \n. "Mac" used today should refer to contemporary computers, just as "Windows" refers to XP or vista unless otherwise qualified.
Saying Macs use \r is about as correct as saying that "Windows runs on top of MS-DOS, supports only the FAT16 filesystem, and has no 64-bit support."
Nobody should ever ever use \r for anything under any circumstances. Unless they are targeting old-ass macs.
You may also want to do a php info call to have a look at a lot of the configuration settings on your PHP setup, code is simple: