开发者

Is there a way to force PHP on Windows to provide paths with forward slashes?

开发者 https://www.devze.com 2023-03-16 12:12 出处:网络
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);

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消