首頁  >  文章  >  後端開發  >  PHP方法處理微信暱稱特殊符號過濾

PHP方法處理微信暱稱特殊符號過濾

coldplay.xixi
coldplay.xixi轉載
2020-07-06 16:07:403434瀏覽

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;
}

相關學習推薦:PHP程式設計從入門到精通

以上是PHP方法處理微信暱稱特殊符號過濾的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:liqingbo.cn。如有侵權,請聯絡admin@php.cn刪除