PHP 8.5.0 Alpha 1 available for testing

php_uname

(PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)

php_uname Returns information about the system running PHP

explain

php_uname ( string $mode = "a" ): string

php_uname() The description of the operating system running PHP is returned. This and phpinfo() The top output is the same string. If you only want to get the name of the operating system. Consider using constants PHP_OS , but please note that this constant will include the PHP build( built )The name of the operating system when.

On some old UNIX platforms, it may not be able to detect the information of the current system, and then it will revert to the system information when building PHP. This only happens when your uname() function library does not exist or cannot be run.

parameter

mode

mode It is a single character used to define what information to return:

  • 'a' : This is the default. Returns a separate mode separated by spaces 's' , 'n' , 'r' , 'v' , 'm' Same information.

  • 's' : Operating system name. For example: FreeBSD
  • 'n' : hostname. For example: localhost.example.com
  • 'r' : Version name, for example: 5.1.2-RELEASE
  • 'v' : Version information. Operating systems are very different.
  • 'm' : Machine type. For example: i386

Return value

Returns the description string.

Update log

edition explain
8.4.0 When specified mode Throw when invalid ValueError

Example

Example # 1 Some php_uname() Example

<?php
echo php_uname ();
echo
PHP_OS ;

/*For example, some will output:
Linux localhost 2.4.21-0.13mdk #1 Fri Mar 14 15:08:06 EST 2003 i686
Linux

FreeBSD localhost 3.2-RELEASE #15: Mon Dec 17 08:46:02 GMT 2001
FreeBSD

Windows NT XN1 5.1 build 2600
WINNT
*/

if ( strtoupper ( substr ( PHP_OS , zero , three )) === 'WIN' ) {
echo
'This is a server using Windows!' ;
} else {
echo
'This is a server not using Windows!' ;
}

?>

It is also convenient to use some related PHP predefined constants , for example:

Example # 2 Examples of some system related constants

<?php
// *nix
echo DIRECTORY_SEPARATOR ; // /
echo PHP_SHLIB_SUFFIX ; // so
echo PATH_SEPARATOR ; // :

// Win*
echo DIRECTORY_SEPARATOR ; // \
echo PHP_SHLIB_SUFFIX ; // dll
echo PATH_SEPARATOR ; // ;
?>

See

Add Notes

Notes contributed by users 1 note

seven
Grzechooo+php at gmail dot com
12 years ago
Note that PHP won't tell you that it reverted to displaying platform it was built on.
 To Top