How to solve the bug that emoji expressions cannot be sent on the front end

php中世界最好的语言
Release: 2017-11-27 14:42:59
Original
3374 people have browsed it

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>
Copy after login

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(&#39;emojiText&#39;);
cosnoel.log(jEmoji. unifiedToHTML(text.value))
Copy after login

If you use commenJS specification

$ npm install emoji
var emoji = require('emoji');
console.log('
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!