about insert emoji to mysql (messy code)
Closed this issue Β· 1 comments
arleyGuoLei commented
hello,I directly get the readText
value insert into mysql , a part of (90%) will messy code.
mysql already use utf8mb4 and link of utf8mb4.
INSERT INTO `ar_mediaset` (`media_id`,`no_search`,`content_t`) VALUES ('gh_01ac1cbf92e1','沑ζΎε°','πβοΈβοΈπΎπ±π
π»π¨π―ππ΄');
what should I do, can solve the quesition ??? HELP.
arleyGuoLei commented
charToUnicode(str) {
let temp
let r = ''
for (const val of str) {
temp = val.codePointAt(0).toString(16)
while (temp.length < 4) { temp = '0' + temp }
r += 'ue' + temp.slice(2).padStart(3, '0')
}
return r
}
}
let str = this.charToUnicode(this.readText)
console.log(str)
str = unescape(str.replace(/\u/g, '%u'))
console.log(str) // end, write str to mysql, it will turn to emoji.