码迷,mamicode.com
首页 > Web开发 > 详细

php 正则只保留 汉字 字母 数字

时间:2016-04-04 19:37:08      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:

$str = "?><?》”\"《喂喂喂555?》《|“: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;
}

 

php 正则只保留 汉字 字母 数字

标签:

原文地址:http://www.cnblogs.com/qingsong/p/5352621.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!