Loading... ## Emoji `Emoji`表情随着`IOS`的普及和微信的支持越来越常见,比如这些比较常见的表情:⭐️ ✨ ⚡️。所谓`Emoji`就是一种在`Unicode`位于`\u1F601-\u1F64F`区段的字符。这个显然超过了目前常用的`UTF-8`字符集的编码范围`u0000-uFFFF`。在 `MySQL` 中,`UTF-8`只支持最多 3 个字节,而 `emoji` 是 4 个字节。 ## 原理 `Typecho`默认不支持`emoji`表情,其实不是程序的锅,而是由于编码的问题,只需要将默认的数据库编码`utf8`修改为`utf8mb4`即可,当然别忘了,`utf8mb4`编码只有在`PHP5.5`以后才支持。 ## 目标 简单两步即可让`typecho`支持`emoji` ## 方法 1.修改数据库编码 进入`PhpMyadmin`,选择您的数据库,操作 → 整理 → 选择`utf8mb4_unicode_ci` 2.修改数据库表编码 直接运行以下`sql`语句 ``` alter table typecho_comments convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_contents convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_fields convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_metas convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_options convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_relationships convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_users convert to character set utf8mb4 collate utf8mb4_unicode_ci; ``` 3.修改数据库配置文件 网站根目录数据库配置文件`config.inc.php`,下面是示例: ``` $db->addServer(array ( 'host' => localhost, 'user' => 'youruser', 'password' => 'yourpassword', 'charset' => 'utf8mb4', //修改这一行 utf8 -> utf8mb4 'port' => 3306, 'database' => 'yourdatabase' ), Typecho_Db::READ | Typecho_Db::WRITE); ```<hr class="content-copyright" style="margin-top:50px" /><blockquote class="content-copyright" style="font-style:normal"><p class="content-copyright">版权声明:本文为原创文章,版权归在花,转载请注明出处!</p><p class="content-copyright">原文链接:<a class="content-copyright" target="_blank" href="https://www.zaihua.me/go/aHR0cHM6Ly9ibG9nLmxhb29vby5jbjo4OC9lbW9qaS5odG1s" target="_blank" >https://blog.laoooo.cn:88/emoji.html</a></p></blockquote> Last modification:September 21st, 2020 at 06:04 pm © 允许规范转载 Support 如果觉得我的文章对你有用,请随意赞赏 ×Close Appreciate the author Sweeping payments Pay by WeChat
这样做无法保证最终效果,还差那么一些步骤。
第一步有点模糊,需要找到转换utf8mb4_unicode_ci 这个的窗口