shershen08/emoji-vue

about insert emoji to mysql (messy code)

Closed this issue Β· 1 comments

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.
image

SQL:
image

INSERT INTO `ar_mediaset` (`media_id`,`no_search`,`content_t`) VALUES ('gh_01ac1cbf92e1','ζ²‘ζ‰Ύεˆ°','πŸŽƒβ­οΈβ­οΈπŸŒΎπŸ±πŸ…πŸ»πŸ¨πŸ―πŸ’πŸ΄');

image

what should I do, can solve the quesition ??? HELP.

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.