//utf8mb4表情转换,用于存储
function textEncode($text){
$txtContent=json_encode($text);
//\\\u[0-9a-f]{4}
$txtContent=preg_replace_callback ('#(\\\u263a|\\\u2728|\\\u2b50|\\\u2753|\\\u270a|\\\u261d|\\\u2757|\\\ud[0-9a-f]{3}\\\ud[0-9a-f]{3})#',function($matches){ return addslashes($matches[1]);}, $txtContent);
$txtContent=json_decode($txtContent);
return $txtContent;
}
//表情反转,用于显示
function textDecode($text){
$txtContent=json_encode($text);
$txtContent=preg_replace_callback ('#(\\\u263a|\\\u2728|\\\u2b50|\\\u2753|\\\u270a|\\\u261d|\\\u2757|\\\ud[0-9a-f]{3})#',function($matches){ print_r($matches);return stripslashes($matches[1]);}, $txtContent);
$txtContent=json_decode($txtContent);
return $txtContent;
}
$table = '
微信emoji表情及输入法自带表情存储与显示
最新推荐文章于 2024-09-14 07:08:53 发布
本文介绍了一种针对UTF8MB4编码下特殊字符(如表情符号)的存储与显示转换方法。通过使用PHP实现的textEncode和textDecode函数,确保了数据库中表情符号的正确存储,并能在显示时正常还原。
990

被折叠的 条评论
为什么被折叠?



