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

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

方法二

  1. protected function removeEmoji($clean_text) {
  2. // Match Emoticons
  3. $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
  4. $clean_text = preg_replace($regexEmoticons, '', $clean_text);
  5. // Match Miscellaneous Symbols and Pictographs
  6. $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
  7. $clean_text = preg_replace($regexSymbols, '', $clean_text);
  8. // Match Transport And Map Symbols
  9. $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';
  10. $clean_text = preg_replace($regexTransport, '', $clean_text);
  11. // Match Miscellaneous Symbols
  12. $regexMisc = '/[\x{2600}-\x{26FF}]/u';
  13. $clean_text = preg_replace($regexMisc, '', $clean_text);
  14. // Match Dingbats
  15. $regexDingbats = '/[\x{2700}-\x{27BF}]/u';
  16. $clean_text = preg_replace($regexDingbats, '', $clean_text);
  17. return $clean_text;
  18. }

方法二

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

方法三

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