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!