PHP脚本-检测是否在Linux或Windows下运行? [英] PHP script - detect whether running under linux or Windows?
本文介绍了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上为您提供各种值,例如WIN32
,WINNT
或Windows
.
It will give you various values on Windows like WIN32
, WINNT
or Windows
.
另请参见: 可能的值:PHP_OS 和 查看全文