PHP处理微信昵称特殊符号过滤方法

我们在通过PHP获取微信昵称,并且存于数据库的时候,由于一些昵称带有特殊符号,所以存不进去,这时候我们可以通过下面的方式来处理。

方法二

protected function removeEmoji($clean_text) {

    // Match Emoticons
    $regexEmoticons = '/[x{1F600}-x{1F64F}]/u';
    $clean_text = preg_replace($regexEmoticons, '', $clean_text);

    // Match Miscellaneous Symbols and Pictographs
    $regexSymbols = '/[x{1F300}-x{1F5FF}]/u';
    $clean_text = preg_replace($regexSymbols, '', $clean_text);

    // Match Transport And Map Symbols
    $regexTransport = '/[x{1F680}-x{1F6FF}]/u';
    $clean_text = preg_replace($regexTransport, '', $clean_text);

    // Match Miscellaneous Symbols
    $regexMisc = '/[x{2600}-x{26FF}]/u';
    $clean_text = preg_replace($regexMisc, '', $clean_text);

    // Match Dingbats
    $regexDingbats = '/[x{2700}-x{27BF}]/u';
    $clean_text = preg_replace($regexDingbats, '', $clean_text);

    return $clean_text;
}

方法二

preg_replace("/[x{1F600}-x{1F64F}x{1F300}-x{1F5FF}x{1F680}-x{1F6FF}x{2600}-x{26FF}x{2700}-x{27BF}]/u","","这里是昵称")

方法三

// 过滤掉emoji表情
function filterEmoji($str){
  $str = preg_replace_callback( '/./u',
      function (array $match) {
        return strlen($match[0]) >= 4 ? '' : $match[0];
      },
      $str);
   return $str;
}

温馨提示: 本文最后更新于2024-12-31 20:58:38,某些文章具有时效性,若有错误或已失效,请在下方 留言或联系 蚂蚁官方
© 版权声明
THE END
喜欢就支持一下吧
点赞7赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容