Nicolase 2019-10-23
如果是只想输入中文的话,就这么写,要注意是分gb2312和utf-8的哦:
gb2312:if(!preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/",$str)) utf-8 :if(!preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$str))
去除特殊字符
$regex = "/(\/|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\‘|\`|\-|\=|\\|\||\"){2,}/"; $other = preg_replace($regex,"",$other); $regex = "/(,|。|!|;|:|、|’|‘|【|】|《|》|?|@|#|¥|%|&|\*|(|)|\-|\+|\=|@|…){2,}/"; $other = preg_replace($regex,"",$other);