encountered a problem when typing emoji on the phone (unable to store it in the database).
the reason for the utf8mb4 of the database when it is found after searching for the problem (because emoji is 4 bytes, while utf-8 "s database is 3 bytes).
then get a js function that converts emoji emoticons into utf-8 characters to save
function utf16toEntities(str) { //utf16emoji
var patt=/[\ud800-\udbff][\udc00-\udfff]/g;
str = str.replace(patt, function(char){
var H, L, code;
if (char.length===2) { //
H = char.charCodeAt(0); //
L = char.charCodeAt(1); //
code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00; //
return "&-sharp" + code + ";";
} else {
return char;
}
});
return str;
}
the problem is that I want to convert this function into a PHP function. Please