PHP 转义emoji表情 In PHP | 转码 123456789function 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);} 解码 1234567function userTextDecode($str){ $text = json_encode($str); $text = preg_replace_callback('/\\\\\\\\/i',function($str){ return '\\'; },$text); return json_decode($text);} -------------本文结束感谢您的阅读-------------