How to get the OS on which PHP is running?(如何获取运行 PHP 的操作系统?)
问题描述
为了构建一个 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有很多预定义常量,通常很有用.
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 的手册页;例如(引用):
<?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_OSconstant, but keep in mind this constant will contain the operating system PHP was built on.
这篇关于如何获取运行 PHP 的操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获取运行 PHP 的操作系统?
基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
