First, the problem phenomenon
Save user Nickname to database, iOS user's nickname contains emoticons, insert database error.
Second, analysis
Use JS filter emoji expression of the main reason: input tag entered emoji expression, submit the form after inserting database error.
The reason is because the UTF-8 encoding is likely to be two, three, four bytes. The emoji expression is 4 bytes, while MySQL UTF8 encodes up to 3 bytes, so data cannot be plugged in.
Third, the solution
1. Convert MySQL encoding from UTF8 to UTF8MB4
Linux modified MySQL code, refer to another article: http://ycgit.blog.51cto.com/8590215/1783775
2. Front-end JS Check filter out emoji expression
The following main paste filter emoji JS code
function Filteremoji () {var ranges = [' \ud83c[\udf00-\udfff] ', ' \ud83d[\udc00-\ude4f] ', ' \ud83d[\ude80-\udeff] '; var Emojireg = $ ("#emoji_input"). Val (); Emojireg = Emojireg. Replace (new RegExp (Ranges.join (' | '), ' G '), "));
MySQL inserted emoji expression when the error problem.