php 正则只保留 汉字 字母 数字
程序员文章站
2022-05-22 20:26:28
...
跳至
$str = "?><M<>\"s~!@#$%^&*()+_)(*&dsdffsde~!@#¥%……&*5545445()+——)(*&……%¥#@!~ 电影_后天 230809-peopl.e die我d.(*&^%$#@!!~"; echo match_chinese($str); function match_chinese($chars,$encoding='utf8') { $pattern =($encoding=='utf8')?'/[\x{4e00}-\x{9fa5}a-zA-Z0-9]/u':'/[\x80-\xFF]/'; preg_match_all($pattern,$chars,$result); $temp =join('',$result[0]); return $temp; }