fabiangebert
fabiangebert

Reputation: 2623

How do I properly split a PATH variable in PHP?

I want to split

$path = getenv('PATH');

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

Upvotes: 11

Views: 11021

Answers (4)

David Thomas
David Thomas

Reputation: 253308

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.

Upvotes: 0

gnarf
gnarf

Reputation: 106322

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

$paths = split(PATH_SEPARATOR, getenv('PATH'));

Upvotes: 3

Greg
Greg

Reputation: 321578

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

Upvotes: 21

RaYell
RaYell

Reputation: 70404

Use the PATH_SEPARATOR constant.

Upvotes: 4

Related Questions