Home > Java > javaTutorial > How to solve the problem that the Java processing database does not support emoji emoticons

How to solve the problem that the Java processing database does not support emoji emoticons

PHPz
Release: 2023-05-10 17:34:13
forward
1429 people have browsed it

The encoding of the general database is utf8, and utf8 does not support storing emoticons. When the stored WeChat nickname contains emoticons, garbled characters will appear. There are two solutions:

1. The mysql database is upgraded to version 5.5 or above, and utf8 is changed to utf8mb4. The characters of utf8mb4 can be up to 4 bytes and can store emoticons. Restart the database server. This method may fail;

2. Filtering out emoticons in java code is simple and efficient. The following is a tool class for filtering out emoticons:

import java.util.regex.Matcher;import java.util.regex.Pattern;

public class EmojiUtil {

public static String replace(String input) {

if (!StringUtil.isEmpty(input)) {

String patternStr = "[^\ \u0000-\\uFFFF]";

Pattern pattern = Pattern.compile(patternStr, Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);

Matcher matcher = pattern.matcher(input);

input = matcher.replaceAll("");

}

return input;

}

}

The above is the detailed content of How to solve the problem that the Java processing database does not support emoji emoticons. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
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