微信表情存入数据库错,过滤方法

日期:2019-05-18 浏览:162次

代码为:

$string = preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $string);

如果还需要过滤其他的非法字符:
$string = preg_replace('/[\x{1F600}-\x{1F64F}]/u', '', $string);
$string = preg_replace('/[\x{1F300}-\x{1F5FF}]/u', '', $string);
$string = preg_replace('/[\x{1F680}-\x{1F6FF}]/u', '', $string);
$string = preg_replace('/[\x{2600}-\x{26FF}]/u', '', $string);
$string = preg_replace('/[\x{2700}-\x{27BF}]/u', '', $string);

最终方法为:
function filter_Emoji($string){
    $string = preg_replace('/[\x{1F600}-\x{1F64F}]/u', '', $string);
    $string = preg_replace('/[\x{1F300}-\x{1F5FF}]/u', '', $string);
    $string = preg_replace('/[\x{1F680}-\x{1F6FF}]/u', '', $string);
    $string = preg_replace('/[\x{2600}-\x{26FF}]/u', '', $string);
    $string = preg_replace('/[\x{2700}-\x{27BF}]/u', '', $string);
    $string = preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $string);
    $string = str_replace(array('"','\''), '', $string);
    return addslashes(trim($string));
}

没有评论

发表评论