PHP正则过滤处理微信昵称中emoji字符的方法

167次阅读
没有评论

移除微信昵称中的 emoji 字符:

function removeEmoji($nickname) {$clean_text = "";
  // Match Emoticons
  $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
  $clean_text = preg_replace($regexEmoticons, '', $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;
}

// 过滤掉 emoji 表情 
function filterEmoji($str)
{$str = preg_replace_callback('/./u',
      function (array $match) {return strlen($match[0]) >= 4 ? '' : $match[0];
      },
      $str);
   return $str;
}
正文完
有偿技术支持加微信
post-qrcode
 
评论(没有评论)
验证码