MySQL inserted emoji expression when the error problem.

Source: Internet
Author: User
Tags mysql code ranges

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.