Home > Article > Backend Development > How to process emoji expression packs in APP in php
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 = '') { 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; } }
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!