In HTML, the Chinese phrase “學好好學” can be expressed as “學好好學” In the project, SMS alarms need to be connected, and the data returned by SMS alarms must be in utf8 After further communication, I found out that what was needed was html-utf8; No suitable golang toolkit was found. The packages involved in language transcoding are mainly mahonia, supports data conversion in various formats, gbk, utf8, gb2312 net/html, supports web page transcoding, which changes the conversion of <,>,&,',',. Based on online experience, three versions of conversion are provided: Javascript function ConvUtf8(obj) { returnobj.replace(/[^\u0000-\u00FF]/g,function($0) {returnescape($0).replace(/(%u)(\w{4})/gi, "&#x$2;") }); } JAVA public static String UTF8_html_conv(String str){ StringBuffer stbPreemptionArg = new StringBuffer(); for(int i = 0;i<str.length();i++){ if (str.codePointAt(i) > 255){ stbPreemptionArg.append("&#x"+Integer.toString(str.charAt(i), 16)+";"); }else{ stbPreemptionArg.append(str.charAt(i)); } } return stbPreemptionArg.toString(); } Golang func CovertToHtml(src string) string{ rs := []rune(src) htmlUtf8 := "" for _, r := range rs { rint := int(r) if rint < 128 { htmlUtf8 += string(r) } else { //utf8 = "\\u"+strconv.FormatInt(int64(rint), 16) htmlUtf8 += "&#x"+strconv.FormatInt(int64(rint), 16) + ";" } } return htmlUtf8 } Summarize The above is the method that the editor introduced to you to convert Chinese into UTF-8 in HTML. I hope it will be helpful to you! |
<<: WeChat applet custom menu navigation to achieve staircase effect
>>: A brief discussion on the font settings in web pages
Table of contents Preface iframe implements sandb...
Table of contents Cache function in vue2 Transfor...
Problem Description In the recent background serv...
Maybe you are using include files here, which is u...
1. Help Command 1. View the current Docker versio...
To use Nginx under Windows, we need to master som...
<br />Original source: http://www.a-xuan.cn/...
This article example shares the specific code of ...
Table of contents What is Vuex? Vuex usage cycle ...
We are all familiar with the MySQL count() functi...
Find mirror We can search for images from the Doc...
1. Create users and authorize Creating users and ...
Due to the needs of the project, I plan to study ...
The first one: Using the CSS position property &l...
Two methods to implement Mysql remote connection ...