php DIRECTORY_SEPARATOR code example

Example 1: what is directory_separator in php

Because in different OS there is different directory separator. 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.

Example 2: when should I use a DIRECTORY_SEPARATOR vs a slash

It doesn't matter -- PHP's IO functions will internally convert 
slashes to the appropriate character.

Tags:

Php Example