Now I create a small PHP Application, here I have problem for using file path, because in Windows use this type location C:\Some\Location\index
but in Linux /www/app/index
so when I define the path using this /
but when the application run in window machine it should be problem for this /
.
So here I want to define the DIRECTORY_SEPARATOR both Windows and Linux platform.
“what is directory_separator in php” Code Answer In Windows it's \ in Linux it's /. DIRECTORY_SEPARATOR is constant with that OS directory separator. Use it every time in paths. In you code snippet we clearly see bad practice code. If framework/cms are widely used it doesn't mean that it's using best practice code.
If you prefer to hard-code the directory separator character, you should use the forward slash ( / ) character. It is the only recognized directory separator character on Unix systems, as the output from the example shows, and is the AltDirectorySeparatorChar on Windows.
In Windows you can use either \ or / as a directory separator.
PHP accepts both \
and /
as valid path separators in all OS. So just use /
in your code
For convenience you can write define a shorter constant:
DEFINE('DS', DIRECTORY_SEPARATOR);
and then write your path as:
$path = 'www'.DS.'app'.DS.'index';
Or do I not understand your question?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With