I'm the only Windows developer in my office, and we have a lot of code that looks like this:
$fileName = preg_replace("/^(extend|base)\//", "", $fileName);
$fileName generally comes from FILE or something similar.
In order to get this code to work on my machine, I've had to start a whole bunch of functions with:
$fileName = str_replace("\\", "/", $fileName);
Is there a better way to go about this, like a php.ini setting, or something I can define on my machine specifically, to force PHP to provide files and paths with forward slashes instead of backslashes?
EDIT: Us开发者_Go百科ing DIRECTORY_SEPARATOR is certainly one option, but it entails hours and hours of changing code all over the place.
To clarify, the question is not "how can I change my code", but "is there a setting to force a unix-like directory separator?"
There is a DIRECTORY_SEPARATOR constant defined for you. Use it instead of "/" or "\".
Edit: (Also, I thought (can't check at the moment) that PHP on Windows allowed the use of forward slash just fine.)
Edit 2: Or just do this:
$fileName = preg_replace("/^(extend|base)[\/\\]/", "", $fileName);
精彩评论