php 警告:preg_replace():找不到结束分隔符“/”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30164229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:35:33  来源:igfitidea点击:

Warning: preg_replace(): No ending delimiter '/' found

phppreg-replace

提问by UnleashDchaos

Warning: preg_replace(): No ending delimiter '/' found in C:\wamp\www\upload\upload_demo.php on line 77 I used preg_replace() to replace slash to backslash. But it shows the above warning. Here is the code..

警告:preg_replace():在第 77 行的 C:\wamp\www\upload\upload_demo.php 中找不到结束分隔符 '/' 我使用 preg_replace() 将斜杠替换为反斜杠。但它显示了上述警告。这是代码..

function del_file($file) {
$delete = @unlink($file);
clearstatcache();
if (@file_exists($file)) {
    $filesys = preg_replace("/", "\\", $file);
    $delete = @system("del $filesys");
    clearstatcache();
    if (@file_exists($file)) {
        $delete = @chmod($file, 0775);
        $delete = @unlink($file);
        $delete = @system("del $filesys");
    }
}

回答by panther

Use str_replace, or add delimiters to pattern if you really need preg_replace.

str_replace如果确实需要,请使用,或向模式添加分隔符preg_replace

$filesys = str_replace("/", "\\", $file);

OR

或者

$filesys = preg_replace("~/~", "\\", $file);