Search

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

April 15, 2018 —John Koster

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:

1function windows_os();

#Example Use

Using this function you can write code like so:

1<?php
2 
3if (windows_os()) {
4 // Windows® specific commands or instructions.
5} else {
6 // Anything that is not Windows®.
7}

instead of code like this:

1<?php
2 
3if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
4 // Windows&reg; specific commands or instructions.
5} else {
6 // Anything that is not Windows&reg;.
7}

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.