JS实现:
var str = "ss123ssxF0x9Fx98x82xF0x9F"; str = str.replace(/[^\x00-xFF]/g,""); console.log(str);//ss123ss
PHP实现:
$str = "ss123ssxF0x9Fx98x82xF0x9F"; $str = preg_replace("/[^\x00-xFF]/m", "", $str); echo $str."<br />";//ss123ss
1 if(!preg_match_all("/^[x{4e00}-x{9fa5}A-Za-z0-9_]+$/mu",$str,$matches)){ //UTF-8汉字字母数字下划线正则表达式,如果不匹配,证明字符串非全中文和字母,可能含有标点符号或者表情符号 2 $str = preg_replace("/[^\x00-xFF]/m", "", $str);//执行过滤 3 }