使用场景: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;
}
}
http://download.csdn.net/detail/wangchaoxiaoban/9627690 源码