English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP has a very useful predefined constant PATH_SEPARATOR, we can judge whether the current server is Linux or Windows through this constant. This article will explain to everyone how to use PATH_SEPARATOR to get the type of the current server in PHP.
PATH_SEPARATOR is a predefined constant in PHP, we can directly echo this constant. In Linux system, the constant outputs ":", in Windows system, the constant outputs ";". Therefore, we can judge the current server system type through the output value of PATH_SEPARATOR.
Output result in Linux system:
<?php var_dump(PATH_SEPARATOR ); //Output result: string(1) ":" ?>
Output result in Windows system:
<?php var_dump(PATH_SEPARATOR ); //Output result: string(1) ";" ?>
Write the judgment of the current server system type into a function:
function getOS(){ if(PATH_SEPARATOR == ':'){ return 'Linux'; }else{ return 'Windows'; } }
If you need to judge the current server system type, you can directly call the function above.
Thank you for reading, I hope it can help everyone. Thank you for your support of this site!