Home >Backend Development >PHP Tutorial >Examples of php processing APP emoji expression packs and IOS expression packs and Mysql saving mobile phone expressions

Examples of php processing APP emoji expression packs and IOS expression packs and Mysql saving mobile phone expressions

黄舟
黄舟Original
2017-09-20 09:40:501742browse

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 base64 visible format. The length after conversion is too large, replace it with the corresponding characters and save it 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 Examples of php processing APP emoji expression packs and IOS expression packs and Mysql saving mobile phone expressions. 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