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 = '') { 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 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!