Home >Web Front-end >HTML Tutorial >How to solve the bug that emoji expressions cannot be sent on the front end
When I was doing mobile development before, there was a function to post comments that needed to be implemented. Although this function is relatively simple to implement, when I tested it, I said that the bug that the emoji that comes with the phone failed to send always appeared. So today I will bring you the solution to this BUG
1. Change the database format in the background
Execute the sql statement to change the encoding format of the database to utf8mb4 storage format, this 4-byte The UTF-8 storage format is perfectly compatible with the previous 3-byte storage format, and can directly store emoji expressions. This is the most perfect solution.
2. Use base-64 encoding
For example, you can use base-encode to encode emoji expressions and then store them in UTF-8. Just decode them when you take them out, but I have not tried it.
3. Get rid of emoji expressions
Kill it violently, I guess the PM will not agree to do this
4. Front-end processing
It is to use a third-party plug-in to convert the input emoji into a span tag and assign it the corresponding class, find a lot of emoji and expression pictures, and when sending them to the background, they send span expressions, which can be stored in the background. The advantage of this is that the display will be the same on all devices and will not cause any problems. Ambiguity, of course, the disadvantage is that emoji expressions are being updated. It is possible that the emoji expression image library you find is incomplete, and some expressions cannot be displayed on the page. This requires regular maintenance.
Recommend a more useful plug-in library github.com/node-module…
How to use: First download the emoji plug-in
<link href="http://cdn.staticfile.org/emoji/0.2.2/emoji.css" rel="stylesheet" type="text/css" /> <script src="http://cdn.staticfile.org/emoji/0.2.2/emoji.js"></script>
Map these two code libraries. This plug-in does not need to rely on the jquery library at all
Connect It will be even simpler
var text = document.querySelector('emojiText'); cosnoel.log(jEmoji. unifiedToHTML(text.value))
If you use commenJS specification
$ npm install emoji var emoji = require('emoji'); console.log('
The above is the detailed content of How to solve the bug that emoji expressions cannot be sent on the front end. For more information, please follow other related articles on the PHP Chinese website!