试试这个:
var_dump(preg_replace("@[/\\\]@", "", "h///e/ll\\o\\//\\"));
// Output: string(5) "hello"
Run Code Online (Sandbox Code Playgroud)
或者替代地
var_dump(str_replace(array('\\', '/'), '', 'h///e/ll\\o\\//\\'));
// Output: string(5) "hello"
Run Code Online (Sandbox Code Playgroud)
您不需要正则表达式来删除这些:
$string = str_replace(array('/', '\\'), '', $string);
Run Code Online (Sandbox Code Playgroud)