1. 程式人生 > >php過濾微信特殊字符方案--》2017新版

php過濾微信特殊字符方案--》2017新版

match turn code php filter 過濾特殊字符 rep pre return

/**
* 過濾特殊字符
* @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 ‘‘;
}
}

php過濾微信特殊字符方案--》2017新版