Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php正则表达式到字符串中的低斜杠_Php_Regex - Fatal编程技术网

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

你的预期产出是什么?你的预期产出是什么?你的预期产出是什么?你的预期产出是什么?