

- #Backslash vs forward slash windows 10
- #Backslash vs forward slash code
- #Backslash vs forward slash mac
Just always use forward slashes, like your paths are all for Unix-style operating systems. So, no need to use the DIRECTORY_SEPARATOR constant anyways.
#Backslash vs forward slash code
But there’s another option… PHP Always Accepts Forward SlashesĪlso, importantly, when writing PHP code, you can always use forward slashes in paths, even for code that runs on a Windows machine. Eg instead of path\to\file.php, you would do 'path'. So, theoretically, your PHP code can just use DIRECTORY_SEPARATOR in paths, and you’ll be ok.
#Backslash vs forward slash windows 10
(I suppose a Windows 10 machine using the Linux subsystem will emulate Linux and so use /). There is a constant called DIRECTORY_SEPARATOR, which is / on Unix-style operating systems, and it’s \ on Windows machines. Let me tell what the options are, then their problems. This isn’t a new problem, by any means, and the programming language PHP has given us two different attempts to fix it, but each has problems. So, on Windows machines, the path to a file will look something like this: path\to\file.php, whereas on Unix-style operating systems (even if they’re a virtual machine, like VVV), the paths instead look like path/to/file.php. Plus, if you’re writing code that works with WordPress, there are a few more considerations. But the problem gets worse if the code will be distributed and could be run anywhere. This forward-or-backslashes problem occurs a little when you’re writing code that will only ever run on one machine. This meant that some unit test code expected to find forward slashes, and when it found backslashes, reported an error. It’s been quite a while since any of us at Event Espresso have ran our code on a Windows machine directly, so there were a few problems, chiefly that Windows uses backslashes, \, to separate folders, whereas Unix-style operating systems use forward slashes, /. BackstoryĪt work, I’ve recently had some trouble getting my linux virtual machine VVV to work and so have been trying out a different system that runs my development websites directly on my Windows operating system, Laragon. PHP has two built-in solutions, but both have problems, especially if you’re working with WordPress.

#Backslash vs forward slash mac
on second reading, this whole answer is pretty much useless trivia.When writing out filepaths and URLs, should you use forward slashes / or backslashes \? Windows expects one, whereas Unix-style operating systems (Linux and Mac OSs, primarily) expect another. The API was less than successful (I guess because it wasn't universally supported by applications), and it was removed in later versions. Useless trivia of the day - in some early versions of MS-DOS there was an API to change the command line option switch character (generally from '/' to '-') so the commands could look more Unix-like and the commands would accept '/' as a path separator on the command line. Windows applications and APIs probably accept '\' as a separator in URIs probably because people are familiar with using backslash as a separator on those systems and URIs can also be use to represent local files. URIs are a similar but different animal from file paths, and URIs should always use '/' to separate components. In fact, if I recall correctly, even MS-DOS accepted '/' as a path separator at the API level ever since it started supporting subdirectories (v2.0) - but by that time the '/' character had already been established as the 'switch' character for command line options, so the backslash became the defacto path separator on DOS (and later Windows). So, what is the right way? If there is any, I would say it's the / because UNIX-like operating systems were out there way before Microsoft implemented directory support into their DOS.Īs far as file system path separators go, I believe that on Windows all APIs will accept forward slashes (but perhaps there are some buggy ones that don't) - the problem is that most applications don't accept them (or parse them incorrectly). There are many artifacts of computer history in modern operating systems, which I suppose most people don't realize, but still have a major influence on how they work. MS-DOS 1.0, a quick rebrand of Q-DOS, is a CP/M derived operating system, from which it inherited drive letters (A: C: etc.)Īs in later versions they wanted to add some directory support, they chose to use the \ since the / already had another meaning in their operating system. They used the / character for parameters from programs (program /a /b)

When Microsoft release MS-DOS version 1.0, it did not have directory support. When UNIX was created, or should I rather say UNICS, they chose the / as separator for directories.īack in the days, storage media was rather small, and every directory in the root was another mounted storage device (/bin /lib etc.) The reason for this is a little piece of history.
