Home  >  Article  >  Backend Development  >  How to process emoji expression packs in APP in php

How to process emoji expression packs in APP in php

一个新手
一个新手Original
2017-09-19 09:14:102332browse

Usage scenario: PHP serves as the server to receive the interface data of the APP. Due to the format problem of Mysql, there is no way to directly save the emoticon package.

Solution: Convert the emoticon into a base64 visible format. Due to the length after conversion, If it is too large, replace it with the corresponding characters and save them in the database

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

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

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

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

The above is the detailed content of How to process emoji expression packs in APP in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn