DEV Community


Discussion on: Always use `/` as directory separator in php

c33s profile image
Julian Author

linux user won't notice if their program will return \ on windows. so they don't recognize if a relative path will be exposed to an url somewhere.

anonyco profile image
Jack Giffin • Edited

You don't have to test it on Windows. You just have to do str_replace($url, '\\', '//') at every location in your code which deals with URLs. Backslashes, even encoded ones, are not part of normal common URLs, so this code may even help prevent possible bugs. If you have special needs that require an encoded backslash to be preserved, you can tweak this function. It's that simple.

Furthermore, you really shouldn't be hosting a server on Windows. It's a terrible awful very bad idea. You never know when MS is going to push the next update that's going to crash your server or make the CIA's backdoors to your PC vulnerable or worse. Linux and BSD are where it's at, and any self-respecting dev uses a *nix server.