如何获得运行PHP的操作系统? [英] How to get the OS on which PHP is running?
问题描述
要构建特定于UNIX/DOS的脚本,我需要知道我使用的是哪种操作系统.
For building a unix/dos specific script I need to know on which kind of operating system I am.
我如何获取此信息?
phpinfo();
告诉我更多信息,但不清楚我是否在Unix上运行.
How do i get this information?
phpinfo();
tells me a lot more and not very clear whether I'm running on unix or not.
推荐答案
PHP有许多 <通常有用的strong>预定义常量 .
PHP has many predefined constants that are often useful.
在这里, PHP_OS
是您要寻找的人.
Here, PHP_OS
is the one you are looking for.
例如,在我当前的计算机上,此代码:
For instance, on my current machine, this code :
var_dump(PHP_OS);
送礼:
string 'Linux' (length=5)
您可以通过 php_uname
功能获得一些示例和比较,从而获得 php_uname
的手册页;例如(引用):
You have some examples and comparisons with what the php_uname
function can get you on the manual page of php_uname
; for instance (quoting) :
<?php
echo php_uname();
echo PHP_OS;
/* Some possible outputs:
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!';
}
该页面还显示:
仅用于操作的名称 系统,请考虑使用
PHP_OS
不变,但请记住这一点 常量将包含操作 系统PHP已构建.
For the name of just the operating system, consider using the
PHP_OS
constant, but keep in mind this constant will contain the operating system PHP was built on.
这篇关于如何获得运行PHP的操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!