Cross Platform Directory Slashes In PHP
Published by philipnorton42 on Thu, 10/22/2009 - 12:49I'm not sure where I found this, but I have been using it on a few projects recently and it's helped a lot. It basically detects what system you are on and will give you a constant that keeps hold of the slash for that system.
1 2 3 4 5 6 7 | if (strtoupper(substr(PHP_OS,0,3)) == 'WIN') { // Windows define('SLASH', '\\'); } else { // Linux/Unix define('SLASH', '/'); } |
For example, on a Windows system a file might be in C:\folders\data\, whereas on Linux the file would be in /folders/data/. So if you are given the full path as a string it can be difficult to separate the filename from the directory without knowing what system you are on.
Category:
Comments
Isn't that what
John (not verified) - Wed, 12/23/2009 - 23:34Add new comment