2017-10-11 168 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

相關問題