PHP itself has many system-predefined variables related to running the operating system, and these predefined variables make it easy to determine whether the current system is Windows or Linux or UNIX.
Here is a list of these more practical predefined variables and a little analysis.
Php_uname ()
Php_os
Directory_separator
Path_separatorphp_uname () The meaning of this function is to return information about the system currently running in PHP, and the following is a detailed description of this function:
/**
* Function: Returns information about the system currently running in PHP
* @param string $mode
* ' A ': return all information
* ' s ': the name of the operating system, such as FreeBSD
* ' n ': The name of the host, such as cnscn.org
* ' R ': version name, such as 5.1.2-release
* ' V ': version number of the operating system
* ' m ': core type, e.g. i386
* @return String
*/
String Php_uname ([string $mode]);
Examples of Use:
Echo Php_uname ();
Echo php_uname (' s ');
Php_os
PHP comes with a built-in constant, which returns the server-side operating system identifier, with a value of (WINNT,WIN32, etc.) using the example:
Echo Strtoupper (substr (php_os,0,3)) = = = ' WIN '? ' Windows Server ': ' is not a widnows server ';
Directory_separator PHP comes with a built-in constant that displays the system delimiter command, without any definition and inclusion to use directly.
As we all know, the path delimiter under Windows is \ (and of course, it works on some systems), and the path delimiter on Linux is/,directory_separator the meaning of this constant exists is that different separators are displayed depending on the operating system.
An example of using Directory_separator to determine the operating system type is as follows:
echo directory_separator== ' \ \ '? Windows Server ': ' is not a widnows server ';
Path_separator is a constant, in the Linux system is a ":" Number, Windows is a ";" No.
An example of using Path_separator to determine the operating system type is as follows:
echo path_separator== '; '? ' Windows Server ': ' is not a widnows server ';