涓枃杞崲鎴恏tml涓殑utf-8

鍦℉TML涓紝涓枃鐨勨�滃ソ濂藉涔犫�濆彲浠ヨ〃绀轰负銆�鈥滃ソ濂藉涔犫��

鍦ㄩ」鐩腑锛岄渶瑕佸鎺ョ煭淇″憡璀︼紝鐭俊鍛婅杩斿洖鏁版嵁瑕佹眰鏄痷tf8鐨�

鍚庢潵缁х画娌熼�氾紝鎵嶅彂鐜拌鐨勬槸html-utf8鐨勶紱

娌℃湁鎵惧埌鍚堥�傜殑golang宸ュ叿鍖咃紝娑夊強璇█杞爜鐨勫寘涓昏鏈�

mahonia锛屾敮鎸佸悇绉嶆牸寮忕殑鏁版嵁杞崲锛実bk锛寀tf8锛実b2312

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

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

}

你可能感兴趣的:(涓枃杞崲鎴恏tml涓殑utf-8)