Main idea: Because each emoji expression has a fixed code, in order to avoid garbled expressions on the page, we can convert the expressions into their corresponding entity codes and save
them. The following is the method of JS transcoding
/* Convert emoji characters to solid characters */ var utf16toEntities = function(str) { var patt=/[\ud800-\udbff][\udc00-\udfff]/g; /* Detect utf16 character regular */ str = str.replace(patt, function(char){ var H, L, code; if (char.length===2) { H = char.charCodeAt(0); /* take out the high bit*/ L = char.charCodeAt(1); /* take out the low order */ code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00; /* Conversion algorithm*/ return "&#" + code + ";"; } else { return char; } }); return str; };
Reference: https://www.bbsmax.com/A/A2dmVQBzen/