Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: php_uname - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

phpcredits" width="11" height="7"/> <php_sapi_name
Last updated: Mon, 05 Feb 2007

view this page in

php_uname

(PHP 4 >= 4.0.2, PHP 5)

php_uname — PHPが稼動しているオペレーションシステムに関する情報を返す

説明

string php_uname ( [string mode] )

php_uname() は、PHP が稼動しているオペレーティング システムに関する説明を返します。単に OS の名前を取得したい場合には PHP_OS 定数の利用を考えてください。ただし、 この定数が返すのは PHP が構築された OS の 情報であることに注意しましょう。

Unix では、もし現在稼動中の OS が判定できない場合には PHP が 構築された OS を表示します。

mode は、どのような情報を返すのかを 1 文字で指定します:

  • 'a': デフォルトです。すべてのモードを "s n r v m" の順で返します。
  • 's': オペレーティングシステム名。 例: FreeBSD
  • 'n': ホスト名。 例: localhost.example.com
  • 'r': リリース名。 例: 5.1.2-RELEASE
  • 'v': バージョン情報。 オペレーティングシステムによって大きく変わります。
  • 'm': マシン型。例: i386

例 1737. php_uname() の例

<?php
echo php_uname();
echo
PHP_OS;

/* 出力の例:
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, 0, 3)) === 'WIN') {
   echo
'This is a server using Windows!';
} else {
   echo
'This is a server not using Windows!';
}

?>

関連する 定義済みの定数 を使うほうが簡単なこともあります。例えば:

例 1738. OS関連の定数の例

<?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;      // ;
?>

phpversion(), php_sapi_name(), phpinfo()も参照してください。



add a note add a note User Contributed Notes
php_uname
simon at NOSPAM dot zadra dot org
20-Jan-2006 02:26
Contrary to the last note, PHP_OS does display the OS PHP runs on currently, whereas php_uname() displays the Operating system version via uname.
This has nothing to do with the system PHP was built on.
michiel1978 /*at*/ hotmail /*dot*/ com
12-Dec-2005 07:38
Example 1 in this article is a little bit misleading. The comment on the last block of code says it will output the server's operating system, but in reality (and according to this same article), it will output the operating system on which PHP was built, because it uses the constant PHP_OS.
tac at smokescreen dot org
15-Jan-2005 08:25
In php 4.1.2, php_uname('n') returns a warning about an invalid parameter count.  Change it to @php_uname to hide this warning.

phpcredits" width="11" height="7"/> <php_sapi_name
Last updated: Mon, 05 Feb 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites