表情转码
function userTextEncode($str){
if(! is_string($str)) return $str;
if(!$str || $str=="undefined")return "";
$text = json_encode($str);
$text = preg_replace_callback("/(\\\u[ed][0-9a-f]{3})/i",function($str){
return addslashes($str[0]);
},$text);
return json_decode($text);
}
表情解码
function userTextDecode($str)
{
$text = json_encode($str);
$text = preg_replace_callback('/\\\\\\\\/i', function ($str) {
return '\\';
}, $text);
return json_decode($text);
}
入库时转存的emoji表情有‘\’,被过滤掉了
使用addslashes转义即可
$nick= addslashes(self::userTextEncode($userInfo['nick']));
|