Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm a Windows user and here is my sample code:

echo "Current directory is: " . realpath(".");

Output: Current directory is: C:\wamp\www\test

Actually, I want to return the path in Unix style on WAMP

i.e. C:/wamp/www/test

How can I do that in WAMP?

What are the settings for doing this in WAMP?

share|improve this question
I can't see any sample code. – pavium Dec 27 '09 at 10:17
This is a coding question that might be better answered on SO imo. – ℝaphink Dec 27 '09 at 14:05

DIRECTORY_SEPARATOR will return you / in unix, and \ in Windows.

Not sure whether this answers your question, though.

Is there any reason why you want it to output the path in unix style? You won't be able to access the path.

If you really really want it, you can use str_replace,

share|improve this answer
Maybe he wants to use it with scp/ssh afterwards, or simply use the path in a URL? – ℝaphink Dec 27 '09 at 14:16
Soon Hui: Did you mean DIRECTORY_SEPARATOR? – MainMa Aug 30 '10 at 2:30

Actually, I want to return the path in Unix style on WAMP

i.e. C:/wamp/www/test

It doesn't make any sense to do this - since it's not a real or valid path.

share|improve this answer

The previous answer about PATH_SEPERATOR is wrong. That will give you a semi-colon. You want to use DIRECTORY_SEPARATOR.

share|improve this answer

Unix paths don't begin with a letter, they start with a '/'. Converting Windows paths to Unix paths might not make sense at all, but you can still use str_replace() or preg_replace() in PHP to remove the letter and change the backslashes into slashes.

share|improve this answer

There's no way to change backslashes to slashes globally: these functions use OS features. The best way is just to strtr(realpath('.'), '\\', '/'), but I don't think it's much of use. If your explode() (or anything) is confused with wrong slashes — use regexps: split('\\/', realpath('.'))

Note that strtr() is much faster in replacing single characters than str_replace() suggested by others.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.