0

Hi all,
I am rather new to PHP, but have a fairly ok grasp of software design. My question arises from the fact that I'm getting ready to deploy some scripts etc. to my website which is hosted on a *nix type server. My home / work computer that I'm developing on is windows. My apache server is: Apache HTTP Server Version 2.2 running on my windows XP sp2 desktop. So when I port all of my php code over, do I have to changeall of my directory slashes from whacks to slashes when I do that?

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by leviathan185
0

Hi EggMatters,

To make your code work on either Windows or *nix platforms, use the constant PATH_SEPARATOR in place of a slash. For example:

$stuff = file_get_contents("some_dir". PATH_SEPARATOR."another_dir". PATH_SEPARATOR.$filename);

The constant PATH_SEPARATOR represents "/" on *nix systems and "\" on Windows systems.

Edited by edwinhermann: n/a

0

Hi EggMatters,

To make your code work on either Windows or *nix platforms, use the constant DIRECTORY_SEPARATOR in place of a slash. For example:

$stuff = file_get_contents("some_dir". DIRECTORY_SEPARATOR."another_dir". DIRECTORY_SEPARATOR.$filename);

The constant DIRECTORY_SEPARATOR represents "/" on *nix systems and "\" on Windows systems.

Excellent suggestion. Thanks!

0

a nice little trick I have been shown is to defne a shorter constant for DIRECTORY_SEPARATOR.

<?PHP
   defined('DIRECTORY_SEPARATOR') ? null : define('DS', DIRECTORY_SEPARATOR); 
?>

you dont need to do the defined part its just incase DS is later defined as PHP standard constant.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.