/** * 过滤表情 **/ function parseEmojiTounicode($stremoji) { $text = preg_replace_callback('/[\xf0-\xf7].{3}/', function($r) { return '@E' . base64_encode($r[0]);}, $stremoji); return $text; } /** * 解析表情 **/ function parseHtmlemoji ($text) { $text_r = preg_replace_callback('/@E(.{6}==)/', function($r) {return base64_decode($r[1]);}, $text); return $text_r; } echo parseEmojiTounicode('💥💥'); echo parseHtmlemoji('@E8J+SpQ==@E8J+SpQ==');
网上说mysql存储emoji必须是5.5.3+,对于linux小白来讲升级mysql风险仍是蛮大的,再者图省事,因此可使用这个折衷的方法。php