zoukankan      html  css  js  c++  java
  • 没有设置数据库编码为utf8mb4时 emoji表情存储

    //对emoji表情转义,存入时使用
        public function emoji_encode($str) {
            $strEncode = '';
            $length = mb_strlen($str, 'utf-8');
            for ($i = 0; $i < $length; $i++) {
                $_tmpStr = mb_substr($str, $i, 1, 'utf-8');
                if (strlen($_tmpStr) >= 4) {
                    $strEncode .= '[[EMOJI:' . rawurlencode($_tmpStr) . ']]';
                } else {
                    $strEncode .= $_tmpStr;
                }
            }
            return $strEncode;
        }
        //对emoji表情转反义,取出数据时使用
        public function emoji_decode($str) {
           $strDecode = preg_replace_callback('|[[EMOJI:(.*?)]]|',               
      function($matches) {
               return rawurldecode($matches[1]);
           }, $str);
           return $strDecode;
        }
     
    如果你设置了编码为utf8mb4还是存不了emoji表情你可以看看这篇文章http://www.lanxinbase.com/?p=1952
  • 相关阅读:
    Windows下使用nmake编译C/C++的makefile
    poj 1228
    poj 1039
    poj 1410
    poj 3304
    poj 1113
    poj 2074
    uva 1423 LA 4255
    poj 1584
    poj 3277
  • 原文地址:https://www.cnblogs.com/kongcode/p/14249940.html
Copyright © 2011-2022 走看看