php正则:仅保留汉字,字母,数字去除其它内容

2016/04/05 2764点热度 0人点赞 0条评论

php正则:只保留汉字,字母,数字去除其它内容

$str = "?><?》”\"《我爱php哈哈哈哈?》《|“:L}{P+_)In thsdff0?><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;
}

幸运猪头

保持饥渴的专注,追求最佳的品质