Laravel 5: Checking if the Script is Executing on a Windows Machine With windows_os

Laravel 5: Checking if the Script is Executing on a Windows Machine With windows_os

Laravel 5

The windows_os helper function can be used to determine if the host server is running a Microsoft Windows® operating system. The function returns either true—if the server is running Windows®—or false—if the server is not running Windows®.

Signature

The signature of the windows_os function is:

function windows_os();

Example Use

Using this function you can write code like so:

<?php

if (windows_os()) {
    // Windows® specific commands or instructions.
} else {
    // Anything that is not Windows®.
}

instead of code like this:

<?php

if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
    // Windows&reg; specific commands or instructions.
} else {
    // Anything that is not Windows&reg;.
}

Start the Discussion

Leave a comment

Subscribe to our newsletter