Determine OS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Determine OS

Post by alex.barylski »

Currently I'm using the PHP_OS constant

I need to determine if I'm on Windows or a *nix because I have a script which splits() paths on directory delimiters...

Code: Select all

$arr1 = split('/', strtolower($path1));
Should I use this OS specific approach or can I use regex to split on either?

On Windows can you not use both / or \ slash to delimit directories?

The code above only works on my production server *nix, but when I tried it on my desktop obviously it crapped all over me :roll:

What is a good, cross platform way of spliting a path into individual directory units?

Cheers :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ahem:

Code: Select all

DIRECTORY_SEPARATOR
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

feyd wrote:ahem:

Code: Select all

DIRECTORY_SEPARATOR
Oh nice :)

You da' man brah!!!
Post Reply