��HTML�У����ĵ�“�ú�ѧϰ”���Ա�ʾΪ“�ú�ѧϰ”
����Ŀ�У���Ҫ�ԽӶ��Ÿ澯�����Ÿ澯��������Ҫ����utf8��
����������ͨ���ŷ���Ҫ����html-utf8 �ģ�
û���ҵ����ʵ�golang���߰����漰����ת��İ���Ҫ��
mahonia��֧�ָ��ָ�ʽ������ת����gbk��utf8��gb2312
net/html��֧����ҳת�룬�ĵ���ת����ҳ�е�<,>,&,',',.
�������Ͼ��飬�ṩ�����汾��ת��:
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
}
�ܽ�
����������С�����ҽ��ܵ�����ת����html�е�utf-8�ķ�����ϣ���Դ������������