Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Senior Member straight_up's Avatar
    Join Date
    Dec 2003
    Location
    Pennsylvania/Arizona
    Posts
    601
    Member #
    4309
    If you always use the forward slash, "/", which is used in UNIX/Linux and works in Windows, instead of the backwards slash, "\", which is Windows' default directory separator (stupid since it's typically an escape character in, let's see, every programming language ever), can you avoid using [minicode]DIRECTORY_SEPARATOR[/minicode]?

    I want the code I'm writing to be as portable as possible. However, [minicode]DIRECTORY_SEPARATOR[/minicode] is annoying to use and makes code a bit less readable.

    (I don't want speculation -- do you know if "/" is always OK as a directory separator on all PHP platforms?)

    Also, my current IP, at work, is blacklisted as spamming (IDK why) - would someone please post
    @Joel: The PATH_SEPARATOR constant will be a colon or semicolon based on the current platform (similar to DIRECTORY_SEPARATOR). Use it when modifying the include_path.
    with name "alan hogan" to http://us3.php.net/ini_set please?
    I am Alan Hogan (@alanhogan on Twitter). I like PHP, UI/UX design, and OS X.

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    I have personally never seen / fail as a directory separator on any platform. However, if the variable exists, it must exist for a reason. I would suggest using it, just to be certain. If you really want to, you can always create a function that takes a string and converts it to use DIRECTORY_SEPARATOR instead of /s. So you'd do something like [minicode]path_fix('home/magic')[/minicode] and you'd get the equivalent of having used DIRECTORY_SEPARATOR. If you start needing to have escaped slashes, however, that gets nasty.

  4. #3
    Senior Member straight_up's Avatar
    Join Date
    Dec 2003
    Location
    Pennsylvania/Arizona
    Posts
    601
    Member #
    4309
    Quote Originally Posted by Shadowfiend
    I have personally never seen / fail as a directory separator on any platform. However, if the variable exists, it must exist for a reason. I would suggest using it, just to be certain. If you really want to, you can always create a function that takes a string and converts it to use DIRECTORY_SEPARATOR instead of /s. So you'd do something like [minicode]path_fix('home/magic')[/minicode] and you'd get the equivalent of having used DIRECTORY_SEPARATOR. If you start needing to have escaped slashes, however, that gets nasty.
    You've used it on Windows? What all platforms?
    I am Alan Hogan (@alanhogan on Twitter). I like PHP, UI/UX design, and OS X.

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Yes, including Windows. I still use \ on Windows most of the time because it's `the right way', and I have heard rumors of problems with using /. Still, every time I have used / (usually accidentally), it has worked fine.

  6. #5
    Senior Member straight_up's Avatar
    Join Date
    Dec 2003
    Location
    Pennsylvania/Arizona
    Posts
    601
    Member #
    4309
    Quote Originally Posted by Shadowfiend
    Yes, including Windows. I still use \ on Windows most of the time because it's `the right way', and I have heard rumors of problems with using /. Still, every time I have used / (usually accidentally), it has worked fine.
    You write PHP specific to the platform?
    I am Alan Hogan (@alanhogan on Twitter). I like PHP, UI/UX design, and OS X.

  7. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Oh no, hardly. The directory separator issue isn't a PHP-only issue

  8. #7
    Senior Member straight_up's Avatar
    Join Date
    Dec 2003
    Location
    Pennsylvania/Arizona
    Posts
    601
    Member #
    4309
    I am Alan Hogan (@alanhogan on Twitter). I like PHP, UI/UX design, and OS X.

  9. #8
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    The likely motivation for the DIRECTORY_SEPARATOR variable is probably to be able to know which separator to use when you're being given a path, rather than when you're actually creating one, now that I think of it. Since Windows is using \ by default, you get fed paths that have \ inside them rather than /, and you need to be able to know what to do with them sometimes (like exploding by the directory separator, for example).

  10. #9
    Senior Member straight_up's Avatar
    Join Date
    Dec 2003
    Location
    Pennsylvania/Arizona
    Posts
    601
    Member #
    4309
    Excellent point. I should clarify that on my page.
    I am Alan Hogan (@alanhogan on Twitter). I like PHP, UI/UX design, and OS X.

  11. #10
    Junior Member 'Edward De Leau's Avatar
    Join Date
    Jan 2013
    Posts
    8
    Member #
    34693
    There are more OS's than only nix and windows therefore if you want to write really portable code DIRECTORY_SEPARATOR would be needed (e.g. mac os classic uses : )

    See e.g. http://stackoverflow.com/questions/6...ant-neccessary and http://edward.de.leau.net/is-the-php...-20130121.html


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 01:11 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com