jordanwb Posted August 12, 2008 Share Posted August 12, 2008 By searching google on how to detect the OS(server) with php I found this: php_uname('s') On my server it returns Linux, which is correct, what would it say for Unix, Mac or Windows. Also what about BSD, is that Unix? Link to comment https://forums.phpfreaks.com/topic/119394-solved-reliably-determining-what-os-a-php-script-is-run-on/ Share on other sites More sharing options...
peasepud Posted August 12, 2008 Share Posted August 12, 2008 Im not sure on all the possible answers but I believe that PHP_OS will supply just the OS name rather than all the other gumph that uname supplies. Link to comment https://forums.phpfreaks.com/topic/119394-solved-reliably-determining-what-os-a-php-script-is-run-on/#findComment-615091 Share on other sites More sharing options...
jordanwb Posted August 12, 2008 Author Share Posted August 12, 2008 Well on my server it says Linux, which is also correct. I need the info to determine line endings for writing files in PHP. Link to comment https://forums.phpfreaks.com/topic/119394-solved-reliably-determining-what-os-a-php-script-is-run-on/#findComment-615092 Share on other sites More sharing options...
trq Posted August 12, 2008 Share Posted August 12, 2008 I need the info to determine line endings for writing files in PHP. As far as I'm aware all operating systems use \n except windows which I believe is \n\r Link to comment https://forums.phpfreaks.com/topic/119394-solved-reliably-determining-what-os-a-php-script-is-run-on/#findComment-615096 Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 You can just use the PHP_EOL constant. Link to comment https://forums.phpfreaks.com/topic/119394-solved-reliably-determining-what-os-a-php-script-is-run-on/#findComment-615100 Share on other sites More sharing options...
discomatt Posted August 12, 2008 Share Posted August 12, 2008 I simply use this function fix_endline( $string ) { return str_replace( array("\r\n", "\r"), "\n", $string ); } Converts all possible 'alternate' endline combinations (\r\n = Windows, \r = OS9 ) to simply \n and is quite fast. Link to comment https://forums.phpfreaks.com/topic/119394-solved-reliably-determining-what-os-a-php-script-is-run-on/#findComment-615112 Share on other sites More sharing options...
jordanwb Posted August 12, 2008 Author Share Posted August 12, 2008 I need the info to determine line endings for writing files in PHP. As far as I'm aware all operating systems use \n except windows which I believe is \n\r Apparently Mac uses a solitary \r. But Mac OS X may use \n because Mac OS X is basically a unix based OS. You can just use the PHP_EOL constant. Now that's convenient. I simply use this function fix_endline( $string ) { return str_replace( array("\r\n", "\r"), "\n", $string ); } Converts all possible 'alternate' endline combinations (\r\n = Windows, \r = OS9 ) to simply \n and is quite fast. But that may not give you the right one. For Widnows having a solitary \n will screw up editing the file with notepad or whatever. Link to comment https://forums.phpfreaks.com/topic/119394-solved-reliably-determining-what-os-a-php-script-is-run-on/#findComment-615133 Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 You can just use the PHP_EOL constant. Now that's convenient. Indeed it is. And you can always put it into a variable if you want, or just do something like: $string = "foo\nbar"; $fixed = str_replace("\n", PHP_EOL, $string); Link to comment https://forums.phpfreaks.com/topic/119394-solved-reliably-determining-what-os-a-php-script-is-run-on/#findComment-615137 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.