utf8编码表达式
/[\x{4e00}-\x{9fa5}a-zA-Z0-9]/u
非utf8编码表达式
/[\x80-\xFF]/
<?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中文
?>
可以解决的事情不用担心;不能解决的事情担心也没用。
原文:https://www.cnblogs.com/afeige/p/14754195.html