问题描述
php使用正则表达式过滤特殊的字符
示例
<?php
function replaceSpecialChar($strParam){
$regex = "/\/|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\-|\=|\\\|\|/";
return preg_replace($regex,"",$strParam);
}
$str = "abcde~!@#$%^&*()_+{}:|<>?,./;'[]\-=`xtz";
$str = replaceSpecialChar($str);
echo "$str\n";
?>