Php 删除正则表达式中的所有斜杠
我有字符串Php 删除正则表达式中的所有斜杠,php,regex,replace,Php,Regex,Replace,我有字符串“h///e/ll\\o\//\”。 需要删除它的所有斜杠来回斜杠多次有人能告诉我正则表达式这样做吗 它用于php preg_replace() 试试这个: var_dump(preg_replace("@[/\\\]@", "", "h///e/ll\\o\\//\\")); // Output: string(5) "hello" 或者交替地 var_dump(str_replace(array('\\', '/'), '', 'h///e/ll\\o\\//\\')); //
“h///e/ll\\o\//\”
。
需要删除它的所有斜杠来回斜杠多次有人能告诉我正则表达式这样做吗
它用于php preg_replace() 试试这个:
var_dump(preg_replace("@[/\\\]@", "", "h///e/ll\\o\\//\\"));
// Output: string(5) "hello"
或者交替地
var_dump(str_replace(array('\\', '/'), '', 'h///e/ll\\o\\//\\'));
// Output: string(5) "hello"
您不需要正则表达式来删除这些:
$string = str_replace(array('/', '\\'), '', $string);