问题
I want to split
$path = getenv('PATH');
into its components. How do I determine the separator char in an os-dependent fashion?
回答1:
You can use the PATH_SEPARATOR
constant, then the DIRECTORY_SEPARATOR
constant to split the path if needed.
See Directory Predefined Constants
回答2:
Use the PATH_SEPARATOR
constant.
回答3:
I know this works for the include_path - not sure about getenv('PATH'):
$paths = split(PATH_SEPARATOR, getenv('PATH'));
回答4:
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.
来源:https://stackoverflow.com/questions/1259450/how-do-i-properly-split-a-path-variable-in-php