微信emoji表情包存入数据库报错处理
public function emoji_encode($nickname)
{
$strEncode = '';
$length = mb_strlen($nickname, 'utf-8');
for ($i = 0; $i < $length; $i++) {
$_tmpStr = mb_substr($nickname, $i, 1, 'utf-8');
if (strlen($_tmpStr) >= 4) {
$strEncode .= '[[EMOJI:' . rawurlencode($_tmpStr) . ']]';
} else {
$strEncode .= $_tmpStr;
}
}
return $strEncode;
}
public function emoji_decode($str)
{
$strDecode = preg_replace_callback('|
\[EMOJI:(.∗?)
\]|', function ($matches) {
return rawurldecode($matches[1]);
}, $str);
return $strDecode;
}