微信emoji表情及输入法自带表情存储与显示

本文介绍了一种针对UTF8MB4编码下特殊字符(如表情符号)的存储与显示转换方法。通过使用PHP实现的textEncode和textDecode函数,确保了数据库中表情符号的正确存储,并能在显示时正常还原。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    //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 = '
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值