How do I properly split a PATH variable in PHP?

前端 未结 4 759
囚心锁ツ
囚心锁ツ 2021-01-11 15:43

I want to split

$path = getenv(\'PATH\');

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

相关标签:
4条回答
  • 2021-01-11 16:17

    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.

    0 讨论(0)
  • 2021-01-11 16:36

    Use the PATH_SEPARATOR constant.

    0 讨论(0)
  • 2021-01-11 16:37

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

    $paths = split(PATH_SEPARATOR, getenv('PATH'));
    
    0 讨论(0)
  • 2021-01-11 16:41

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

    0 讨论(0)
提交回复
热议问题