微信nickname中的表情替换成*号存储到数据库

function replaceEmoji($nickname,$replaceStr="*")
{
    //$nickname = json_decode('{"nickname":"\ue131\u6f6e\u978b\uff5e\u9ad8\u6893\u94b0\ud83d\udc5f\ud83d\udc5f\ud83d\udc5f"}');
    //var_dump($nickname);
    $nicknameTmp         = json_encode($nickname);
    //var_dump($nicknameTmp);
    //$nicknameTmp = preg_replace("#(\\\ue[0-9a-f]{3})#ie","addslashes('\\1')",$nicknameTmp);
    $nicknameTmp         = preg_replace("#(\\\ue[0-9a-f]{3})#i",$replaceStr,$nicknameTmp);
    $nicknameNoEmoji     = json_decode($nicknameTmp);
    return $nicknameNoEmoji;
}

参考了别人的代码,正则替换成*号或者其他符号,微信传过来的是Unicode,但数据库无法存储,目前只做了最简单的处理。

Related posts:

Leave a Reply

Your email address will not be published.