1

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?

  • 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
3

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,

  • 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? – Arseni Mourzenko Aug 30 '10 at 2:30
1

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.

1

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

0

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy