Search code examples
phppathoperating-system

What Path is acceptable?


I am using below statement to return the directory name of the running script:

print dirname(__FILE__);

It outputs something like this with back-slashes:

www\EZPHP\core\ezphp.php

Question:

Is a path with back-slashes acceptable across all major operating systems? If not, how should I construct the path either with slashes or back-slashes so that it is acceptable on all major operating systems eg Windows, Linux, Ubuntu.


Solution

  • Forward slashes are a good route.

    There is also a constant called DIRECTORY_SEPARATOR that will return the directory separator for the system the code is running on.

    I use forward slashes when I write paths for all my apps, and I often use DIRECTORY_SEPARATOR when I am exploding the results of a call that returns a path so that I can ensure I always have the right one to break on.

    HTH, Jc