過濾微信昵稱/QQ昵稱中的特殊字符
PHP只保留中文,英文以及數字的正則表達式
utf8編碼表達式
/[\x{4e00}-\x{9fa5}a-zA-Z0-9]/u
非utf8編碼表達式
/[\x80-\xFF]/
PHP過濾只保留中文,英文以及數字的方法
<?php function matchChinese($chars,$encoding='utf8'){ $pattern =($encoding=='utf8')?'/[\x{4e00}-\x{9fa5}a-zA-Z0-9]/u':'/[\x80-\xFF]/'; preg_match_all($pattern,$chars,$result); return join('',$result[0]); }$str = "abc中文。,?#😘🐕%^&())*(&^";
echo matchChinese($str); //abc中文
?>
可以解決的事情不用擔心;不能解決的事情擔心也沒用。