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,而不是cl系统黑板)
Update
为了澄清问题,该笔文字从指挥线上操作。
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,而不是cl系统黑板)
为了澄清问题,该笔文字从指挥线上操作。
光盘将给您各种Windows值,如WIN32
、WINNT
或Windows/code>。
另见:。 价值:PHP_OS和php_uname
<<>>><>>><>>>><>Docs/em><>:
if (strtoupper(substr(PHP_OS, 0, 3)) === WIN ) {
echo This is a server using Windows! ;
} else {
echo This is a server not using Windows! ;
}
您可以检查一下名录分离器是否为/
(关于unix/linux/mac)或/code>。 姓名为<代码> DIRECTORY_SEPARATOR
。
if (DIRECTORY_SEPARATOR === / ) {
// unix, linux, mac
}
if (DIRECTORY_SEPARATOR === \ ) {
// windows
}
if (strncasecmp(PHP_OS, WIN , 3) == 0) {
echo This is a server using Windows! ;
} else {
echo This is a server not using Windows! ;
}
似乎比接受的答案更可取。 然而,与DIRECTORY-SEPARATOR进行上述检测是最快的。
从PHP 7.2.0开始,你可以使用固定的<代码”探测O.S.。 PHP_OS_FAMILY :
if (PHP_OS_FAMILY === "Windows") {
echo "Running on Windows";
} elseif (PHP_OS_FAMILY === "Linux") {
echo "Running on Linux";
}
See the official PHP documentation for its possible values.
http://php.net/manual/en/Function.php-uname.php PHP_OS报告说,PHP是built on,但不一定是目前运行的同一处。
如果您在PHP >=5.3,并且仅需要了解您是否在Windows或Dod-Windows上运行,然后测试 定义可以是好的主轴,例如:
$windows = defined( PHP_WINDOWS_VERSION_MAJOR );
echo php_uname();
根据http://nl3.php.net/manual/en/maind.constants.php#113172“rel=“noreferer” 所有权=“Prefin Constants:user Contributed Notes” 预定用户配制说明 沃尔克和尔加索解决办法,你可以简单地创造这样的帮助阶层:
<?php
class System {
const OS_UNKNOWN = 1;
const OS_WIN = 2;
const OS_LINUX = 3;
const OS_OSX = 4;
/**
* @return int
*/
static public function getOS() {
switch (true) {
case stristr(PHP_OS, DAR ): return self::OS_OSX;
case stristr(PHP_OS, WIN ): return self::OS_WIN;
case stristr(PHP_OS, LINUX ): return self::OS_LINUX;
default : return self::OS_UNKNOWN;
}
}
}
<><>Usage:
if(System::getOS() == System::OS_WIN) {
// do something only on Windows platform
}
这一工作应在PHP4.3+中进行:
if (strtolower(PHP_SHLIB_SUFFIX) === dll )
{
// Windows
}
else
{
// Linux/UNIX/OS X
}
To detect whether it s Windows, OS X or Linux:
if (stripos(PHP_OS, win ) === 0) {
// code for windows
} elseif (stripos(PHP_OS, darwin ) === 0) {
// code for OS X
} elseif (stripos(PHP_OS, linux ) === 0) {
// code for Linux
}
<代码>stripos在本特定情况下比>substr
慢一些,但对于这种小的任务而言,其效率是足够的,而且更为合理。
www.un.org/Depts/DGACM/index_spanish.htm Core Prefin Constants: http://us3.php.net/manual/en/servd.constants.php 编号PHP_OS (string)
不变。
或者如果你想发现客户的协调人:
<?php
echo $_SERVER[ HTTP_USER_AGENT ] . "
";
$browser = get_browser(null, true);
print_r($browser);
?>
http://us3.php.net/manual/en/Function.get-browser.php rel=“nofollow noreferer” http://us3.php.net/manual/en/Function.get-browser.php
根据您的编辑,您可参考这一可疑的。 PHP 页: 1
You can use
string php_uname ([ string $mode = "a" ] )
So
php_uname("s")
s : Operating system name. eg. FreeBSD.
http://php.net/manual/en/Function.php-uname.php” rel=“nofollow noreferer” http://php.net/manual/en/Function.php-uname.php
如果你想要检查一下是否在含水层下运行,那么就在<代码>(PHP_OS===LC/LC/LC/ LC/code>上进行测试。 无需使用梯子和子体。
function isWin(){
if (strtolower(substr(PHP_OS, 0, 3)) === win || PHP_SHLIB_SUFFIX == dll || PATH_SEPARATOR == ; ) {
return true;
} else {
return false;
}
}
For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...
How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks
i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...
Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...
I ve just installed Zend Studio 7.0.2 on my Linux-Ubuntu 9.10 system. There were no problems during the installation but when I try to create a new project, the New Project form hangs when I click ...
I am running valgrind as follows:- /usr/local/bin/valgrind "process_name" After excecution its giving me following error ==21731== ==21731== Warning: Can t execute setuid/setgid executable: ==...
I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...
Is there anything other than DDD that will draw diagrams of my data structures like DDD does that runs on Linux? ddd is okay and runs, just kind of has an old klunky feeling to it, just wanted to ...