将emoji转换成utf8 然后存储到数据库,但是 效率低

 1 public function rrr($text) {
 2         $text = 'a????ss????ss????ss';
 3         //处理名字的emoji符号
 4         $tmpStr = json_encode($text); //暴露出unicode
 5 
 6         $tmpStr1 = preg_replace_callback("#(\\\ue[0-9a-f]{3})#i", function($a) {
 7             //var_dump($a);
 8             return addslashes($a[1]);
 9             //return $a;
10         }, $tmpStr);
11         $text = json_decode($tmpStr1); 
12         return $tmpStr1;
13     }

 

直接mysql支持:需要5.5以上的版本

更换数据库编码 database default character set: utf8mb4.

default collection:utf8mb4_general_ci;



对应的表:comment: default character set: utf8mb4.

default collection:utf8mb4_general_ci;



对应的字段:content: character set: utf8mb4.    collection:utf8mb4_general_ci;

php端 数据库编码 要改成utf8mb4

这样就相对完美了

 

相关文章:

  • 2022-12-23
  • 2021-12-27
  • 2021-06-04
  • 2021-09-18
  • 2022-12-23
  • 2022-01-13
猜你喜欢
  • 2022-12-23
  • 2021-05-21
  • 2022-12-23
  • 2021-09-23
  • 2022-01-08
  • 2022-01-30
  • 2021-07-31
相关资源
相似解决方案