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
Before talking about CSS priority, we need to und...
Table of contents 1. Through HBuilderX visual int...
Preface: Jenkins' Master-Slave distributed ar...
<br />Looking at this title, you may find it...
What is a tree in web design? Simply put, clicking...
background In the group, some students will ask r...
Preface When mysql modified the default database ...
Software and hardware environment centos7.6.1810 ...
The difference between relative and absolute in H...
Cascading and Cascading Levels HTML elements are ...
There is a table user, and the fields are id, nic...
1. Clarify the design direction <br />First,...
Download Nginx image in Docker docker pull nginx ...
1. Prerequisites We use the require.context metho...
Origin of the problem When using docker, I unfort...