PHP 转义emoji表情

WechatIMG129.jpeg

  • 转码
1
2
3
4
5
6
7
8
9
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);
}
  • 解码
1
2
3
4
5
6
7
function userTextDecode($str){
$text = json_encode($str);
$text = preg_replace_callback('/\\\\\\\\/i',function($str){
return '\\';
},$text);
return json_decode($text);
}
-------------本文结束感谢您的阅读-------------
0%