更新时间:2022-12-11 08:06:27
您需要在preg_replace
参数中对它们进行双重转义"(一次用于字符串,一次用于regex引擎):
You need to "double escape" them inside preg_replace
parameters (once for the string, once for the regex engine):
$mystring = 'c:\windows\system32\drivers\etc\hosts';
$escaped = preg_replace('/\\\\/','\\\\\\\\',$mystring);
echo "New string is: $escaped\n";
或如果使用str_replace
仅一次:
$newstring = str_replace('\\','\\\\',$mystring);
echo "str_replace : $newstring\n";
?>