php正则表达式到字符串中的低斜杠
这里是我的正则表达式,它排除特殊字符,然后允许少数字符,如(-,%,:,@)。我想允许php正则表达式到字符串中的低斜杠,php,regex,Php,Regex,这里是我的正则表达式,它排除特殊字符,然后允许少数字符,如(-,%,:,@)。我想允许/也出现问题 return preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%:@&-]/s', '', $string); 这对于列出的特殊角色很好,但是 return preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%\\:&-]/s', '', $string); 不过滤lchracter to 以下是测试的链接: 在
/
也出现问题
return preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%:@&-]/s', '', $string);
这对于列出的特殊角色很好,但是
return preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%\\:&-]/s', '', $string);
不过滤l
chracter to
以下是测试的链接:
在url中不允许
\\
。我想像往常一样显示URL您在通过http:\\
输入http://
时犯了错误,而且您的正则表达式需要在排除列表中包含/
。这应该起作用:
function clean($string) {
// Replaces all spaces with hyphens.
$string = str_replace(' ', '-', $string);
// Removes special chars.
return preg_replace('~[^\w %\[\].()%\\:@&/-]~', '', $string);
}
$d = clean("this was http://nice readlly n'ice 'test for@me to") ;
echo $d; // this-was-http://nice-readlly-nice-test-for@me-to
您在通过
http:\\
输入http://
时出错,您的正则表达式还需要将/
包含在排除列表中。这应该起作用:
function clean($string) {
// Replaces all spaces with hyphens.
$string = str_replace(' ', '-', $string);
// Removes special chars.
return preg_replace('~[^\w %\[\].()%\\:@&/-]~', '', $string);
}
$d = clean("this was http://nice readlly n'ice 'test for@me to") ;
echo $d; // this-was-http://nice-readlly-nice-test-for@me-to
您在通过
http:\\
输入http://
时出错,您的正则表达式还需要将/
包含在排除列表中。这应该起作用:
function clean($string) {
// Replaces all spaces with hyphens.
$string = str_replace(' ', '-', $string);
// Removes special chars.
return preg_replace('~[^\w %\[\].()%\\:@&/-]~', '', $string);
}
$d = clean("this was http://nice readlly n'ice 'test for@me to") ;
echo $d; // this-was-http://nice-readlly-nice-test-for@me-to
您在通过
http:\\
输入http://
时出错,您的正则表达式还需要将/
包含在排除列表中。这应该起作用:
function clean($string) {
// Replaces all spaces with hyphens.
$string = str_replace(' ', '-', $string);
// Removes special chars.
return preg_replace('~[^\w %\[\].()%\\:@&/-]~', '', $string);
}
$d = clean("this was http://nice readlly n'ice 'test for@me to") ;
echo $d; // this-was-http://nice-readlly-nice-test-for@me-to
你的预期产出是什么?你的预期产出是什么?你的预期产出是什么?你的预期产出是什么?