PHP path_separator to determine the current server system type instance _php instance

Source: Internet
Author: User

There is a very useful predefined constant path_separator in PHP that we can use to determine whether the current server is Linux or Windows. This article will explain to you how PHP uses Path_separator to get the type of the current server.

Path_separator is a predefined constant in PHP, and we can directly echo this constant, in a Linux system, the constant output ":" In the Windows system, the constant output ";" Resolution Therefore, we can determine the current server system type by path_separator the output value.

Output results in Linux systems:

<?php
  var_dump (path_separator);
  Output Result: string (1) ":"
?>

To output results in a Windows system:

<?php
  var_dump (path_separator);
  Output Result: string (1) ";"
? >

Write a function that determines the current server system type:

function Getos () {
 if (Path_separator = = ': ') {return
 ' Linux ';
 } else{return
 ' Windows ';
 }

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

Thank you for reading, I hope to help you, thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.