2017-10-11 169 views
0

我已经使用php preg_replace函数只允许来自变量字符串的字母数字字符。代码如下。此代码工作正常。允许一些特殊字符和字母数字字符

但现在我想允许一些特殊字符,如[email protected]#$%^&*()_+/等与字母数字字符一起。这个怎么做?

$hashh=$_GET['hash']; 
$hash = preg_replace("/[^a-zA-Z0-9]+/", "", $hashh); 

回答

0

试一下这个

$regex = "/[^[email protected]#$%^&*()_+\/]+/"; 
$string = "Th3 4ll0w3d P4rt5 4r3 [email protected]#$%^&*()_+/"; 
$preg = preg_replace($regex, '', $string); 
echo $preg; 
+0

我可以用这个还的preg_match? – John

+0

当然''''开头的'^'意思是'Not'因此对于'preg_match',你可以将其删除,它将作为'/ [a-zA-Z0-9〜! @!$%^&*()_ + \ /] + /' – AXAI

+0

还可以,如果(!preg_match(“/ [^ a-zA-Z0-9〜!@#$%^&*()_ + \ /] + /“,$ cpass)) { $ error =”Not valid Password!“; $ code = 3; } – John

相关问题