How do I properly split a PATH variable in PHP?

痴心易碎 提交于 2019-12-08 15:28:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!