Alan Hogan

Feed
  
Written: Sun., January 6th, 2008Updated: 2008-01-09 10:18am  

Portable PHP code: DIRECTORY_SEPARATOR is not necessary

In attempting to write cross-platform, portable PHP code, I used PHP’s DIRECTORY_SEPARATOR constant to write path strings, e.g. "..".DIRECTORY_SEPARATOR."foo", because the “proper” way to do it on Windows would be "..\foo" while on everything else (Linux, UNIX, Mac OS X) it would be "../foo".

Well, as Christian on php.net pointed out and the guys at Web Design Forums confirmed, that’s completely unnecessary. As long as you use the forward slash, “/”, you’ll be OK. Windows doesn’t mind it, and it’s best for *nix operating systems.

(Note that DIRECTORY_SEPARATOR is still useful for things like explode-ing a path that the system gave you. Thanks to Shadowfiend for pointing this out.)

Tagged:                  

Author: You should follow @alanhogan

Original content, graphics, and code © Alan J. Hogan 2000–2010  |  Contact

About this site & credits  |  Powered by HS-CMS

Site map