Home  >  Article  >  Backend Development  >  php PATH_SEPARATOR determines the current server system type instance

php PATH_SEPARATOR determines the current server system type instance

墨辰丷
墨辰丷Original
2018-05-31 10:02:231422browse

This article mainly introduces the relevant information of php PATH_SEPARATOR to determine the current server system type instance. Friends who need it can refer to it

There is a very useful predefined constant PATH_SEPARATOR in php, we can use this constant To determine whether the current server is Linux or Windows. This article will explain to you how php uses PATH_SEPARATOR to obtain the type of the current server.

PATH_SEPARATOR is a predefined constant in php. We can directly echo this constant. In the Linux system, the constant outputs ":". In the Windows system, the constant outputs the ";" sign. . Therefore, we can determine the current server system type through the PATH_SEPARATOR output value.

Output result in linux system:

<?php
  var_dump(PATH_SEPARATOR );
  //输出结果:string(1) ":"
?>

Output result in windows system:

<?php
  var_dump(PATH_SEPARATOR );
  //输出结果:string(1) ";"
?>

Write the judgment of the current server system type into a function:

function getOS(){
 if(PATH_SEPARATOR == &#39;:&#39;){
 return &#39;Linux&#39;;
 }else{
 return &#39;Windows&#39;;
 }
}

If you need to determine the current server system type, you can directly call the above function.

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

Detailed examples of methods to prevent hotlinking in PHP

PHP method to implement WeChat enterprise payment to users

Detailed explanation of the definition and use of PHP exception handling

The above is the detailed content of php PATH_SEPARATOR determines the current server system type instance. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn