Jump to content

Forward slash or back slash


Xu Wei Jie

Recommended Posts

I am not sure if this is a PHP question. Generally, files and directories in Windows use backslash in their paths. Unix and others use forward slash. Correct me if I am wrong.

 

However, I wish to know how php functions(especially the file functions) interpret and handle the slashes. Is it platform independent? Sometimes, I do get errors when using the wrong slash.

 

Please advise me on this.

Link to comment
Share on other sites

Thanks Mark. This snippet is very neat. However, there are many values PHP_OS can take. This means I need to find out all the operating systems on how they handle slashes.

 

However, I want php to figure out the slash to use instead of hardcoding based on PHP_OS. Is there such a feature?

 

Anyone has a lot of experience with such file handling in PHP?

Link to comment
Share on other sites

the way i do it is use the predifined constant called DIRECTORY_SEPARATOR

i would redefine it to something like DS to avoid having RLY long paths lol.

 

<?php
define( 'DS'	, DIRECTORY_SEPARATOR );
define( 'BASE' 	, __FILE__ );
$fs_path_array = explode( DS, BASE );
?>

 

works on both unix and windows systems.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.