I’m writing a PHP class, and I want it to be cross-platform compatible. I need to explode a path to find a particular folder name. What do I choose for the delimiter? The path will contain ‘/’ on UNIX and ‘\’ on Windows.
In this particular example, I want to get the name of the directory where an included file is stored. I use this :
private function find_lib_dir() {
$array_path = explode('/', __DIR__);
return $array_path[count($array_path)-1];
}
In this situation (and more generally), what can I do to make sure it will work on both Windows and UNIX?
Thanks!
You can use
DIRECTORY_SEPARATORas follows: