Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

<?php
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
1  
I can't see any sample code. –  pavium Dec 27 '09 at 10:17
1  
This is a coding question that might be better answered on SO imo. –  ℝaphink Dec 27 '09 at 14:05

5 Answers 5

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
2  
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

 
discard

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