views:

1094

answers:

5

I want to split

$path = getenv('PATH');

into its components. How do I determine the separator char in an os-dependent fashion?

+2  A: 

Use the PATH_SEPARATOR constant.

RaYell
+5  A: 

You can use the PATH_SEPARATOR constant, then the DIRECTORY_SEPARATOR constant to split the path if needed. See Directory Predefined Constants

Greg
You cannot use `DIRECTORY_SEPARATOR` for that. You must use `PATH_SEPARATOR`. First one is the character that separates folders from each other, path separator separates differents paths i.e. defined in PATH environmental variable.
RaYell
That's what I get for doing too many things at once :|
Greg
+3  A: 

I know this works for the include_path - not sure about getenv('PATH'):

$paths = split(PATH_SEPARATOR, getenv('PATH'));
gnarf
include_path is a valid PATH style string for whatever system you are on: the same split techniques that work for one will work for the other.
Matthew Scharley
A: 

I seem to remember that Windows will accept both forward- and back-slashes as a file-separator, so you may not have to worry about it.

David Thomas
I think he means the separator for the Entries in the PATH environment variable (e.g. ":" on *nix), not the separator inside the paths.
Chris089
Ahhhh...oops =)
David Thomas