php过滤微信特殊字符方案--》2017新版

/**
* 过滤特殊字符
* @param unknown $str
*/
private function filterStr($str)
{
if($str){
$name = $str;
$name = preg_replace_callback('/\xEE[\x80-\xBF][\x80-\xBF]|\xEF[\x81-\x83][\x80-\xBF]/',function ($matches) { return '';}, $name);
$name = preg_replace_callback('/xE0[x80-x9F][x80-xBF]‘.‘|xED[xA0-xBF][x80-xBF]/S',function ($matches) { return '';}, $name);
$name = json_encode($name);
$name = preg_replace_callback("/\\\ud[0-9a-f]{3}/i", function ($matches) { return '';}, $name);
if(!empty($name))
{
$name = json_decode($name);
return $name;
}else{
return '';
}

}else{
return '';
}
}

posted @ 2017-08-05 15:46  lizhiweii  阅读(509)  评论(0编辑  收藏  举报