0

I am not sure about which platform my code goes to host, so im using directory separator in my code.

I followed this link - how-to-get-a-platform-independent-directory-separator-in-php

but the accepted answer is not what i am looking (string replacement). Although another solution with "DIRECTORY_SEPARATOR" is something what I was looking for but my concern is when i checked the docs at -> dir.constants

They said - The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

So from where I can check whether this extension is available or not, I checked from phpinfo() method but unable to locate under it, how can I locate this whether installed or not ? . If its available in all so can i proceed with this dummy code or not -

$headurl = $_SERVER['SERVER_NAME'].'/'.'backgroundimage.jpg';
Community
  • 1
  • 1
swapnesh
  • 26,318
  • 22
  • 94
  • 126
  • Both unix and windows support `/` so it's safe just to use that for everything. Only time you have to be careful is if you are manipulating (ie comparing/exploding) paths since windows will have `\ ` by default and unix will have `/`. – Supericy Jan 01 '13 at 09:33
  • @Supericy thx for the info & what about checking for directory structure constant whether supported or not ?? – swapnesh Jan 01 '13 at 09:37

2 Answers2

3

These constants are extension dependent but its part of PHP now. See dir.installation.

There is no installation needed to use these functions; they are part of the PHP core.

Even in requirements Its stated

No external libraries are needed to build this extension.

So you dont have to worry about it. Every platform will support this constant

Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187
3

DIRECTORY_SEPARATOR is predefined constant and available in all PHP versions right from the start to ensure cross OS file system compatibility. you can use it.

note: this is also indicated in your reference http://php.net/manual/en/dir.constants.php (by the missing "Available since PHP x.x.x.". e.g. PATH_SEPARATOR is "Available since PHP 4.3.0.").

udo
  • 4,832
  • 4
  • 54
  • 82
  • 1
    yeah thx for mentioning...what i was looking at Director Separator so just forgot to read the lower one ..my bad :( +1 – swapnesh Jan 01 '13 at 09:49