/** * 過濾表情 **/ 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