处理微信昵称中带表情符无法存到数据库问题。数据库需要加长微信昵称字段长度
/**对emoji表情转义
- @param $nickname
- @return string
*/
function emoji_encode($nickname)
{
$strEncode = ‘’;
l e n g t h = m b s t r l e n ( length = mb_strlen( length=mbstrlen(nickname, ‘utf-8’);
for ($i = 0; $i < $length; $i++) {
t m p S t r = m b s u b s t r ( _tmpStr = mb_substr( tmpStr=mbsubstr(nickname, i , 1 , ′ u t f − 8 ′ ) ; i f ( s t r l e n ( i, 1, 'utf-8'); if (strlen( i,1,′utf−8′);if(strlen(_tmpStr) >= 4) {
s t r E n c o d e . = ′ [ [ E M O J I : ′ . r a w u r l e n c o d e ( strEncode .= '[[EMOJI:' . rawurlencode( strEncode.=′[[EMOJI:′.rawurlencode(_tmpStr) . ‘]]’;
} else {
$strEncode .= $_tmpStr;
}
}
return $strEncode;
}
//对emoji表情转反义
function emoji_decode($str)
{
KaTeX parse error: Expected 'EOF', got '\[' at position 37: …ace_callback('|\̲[̲\[EMOJI:(.*?)\]…matches) {
return rawurldecode($matches[1]);
}, $str);
return $strDecode;
}
作者:等灯等灯
来源:CSDN
原文:https://blog.csdn.net/qq_36180117/article/details/80846599
版权声明:本文为博主原创文章,转载请附上博文链接!