PHP 脚本 - 检测是否在 linux 或 Windows 下运行? [英] PHP script - detect whether running under linux or Windows?

查看:37
本文介绍了PHP 脚本 - 检测是否在 linux 或 Windows 下运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PHP 脚本,可以放在 windows 系统或 linux 系统上.无论哪种情况,我都需要运行不同的命令.

I have a PHP script that may be placed on a windows system or a linux system. I need to run different commands in either case.

如何检测我所处的环境?(最好是 PHP 而不是聪明的系统黑客)

How can I detect which environment I am in? (preferably something PHP rather than clever system hacks)

为了澄清,脚本是从命令行运行的.

To clarify, the script is running from the command line.

推荐答案

检查 PHP_OS 常量文档.

它将在 Windows 上为您提供各种值,例如 WIN32WINNTWindows.

It will give you various values on Windows like WIN32, WINNT or Windows.

另请参阅:可能的值:PHP_OSphp_uname文档:

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 脚本 - 检测是否在 linux 或 Windows 下运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆