最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

php处理APP中 emoji表情包的方法

来源:http://www.erdangjiade.com/topic/527.html 你好,世界。 2017-09-25 22:42浏览(51)

使用场景:PHP作为服务器端接收APP的接口数据,由于Mysql 的格式问题导致没有办法直接保存表情包

解决方案;将表情转换成base64可以见格式,由于转换后长度过大,将其替换成对应字符保存入数据库

<?php 
class Emoji
{
    /**
     * 将表情转成对应代表字符串
     * @param string $content
     */
    public static function emojiEncode($content = '')
    {
        if (!$content) {
            return $content;
        }
        $content = json_encode($content);

        $emoji = requrie_once('emoji.php');
        $content = str_replace(array_keys($emoji['regenEncode']), $emoji['regenEncode'], $content);
        $content = json_decode($content, true);
        return $content;
    }

    /**
     * 将对应字符串转成表情
     * @param string $content
     */
    public static function emojiDecode($content = '')
    {
        if (!$content) {
            return $content;
        }
        $content = json_encode($content);

        $emoji = requrie_once('emoji.php');
        $content = str_replace(array_keys($emoji['regenDecode']), $emoji['regenDecode'], $content);
        $content = json_decode($content, true);
        return $content;
    }
}

以上就是php处理APP中 emoji表情包的方法的详细内容,更多请关注二当家的素材网其它相关文章!

评论0
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

1 2