国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

談?wù)刪tml轉(zhuǎn)義字符如何通過代碼識別

2019-10-26 17:14:25
字體:
供稿:網(wǎng)友

偶爾會在數(shù)據(jù)中看到諸如' 這樣的字符,特征如下

以&#開頭,中間是一串?dāng)?shù)字,以;結(jié)尾
以&開頭,中間一串字符,以;結(jié)尾

比如最常見的 或者等價(jià)的 

瀏覽器遇到這些轉(zhuǎn)義符,會轉(zhuǎn)義回來,但如何通過代碼識別? org.apache.commons.lang.StringEscapeUtils.unescapeHtml提供了很好的說明

遇到上面的第一種情況,中間是數(shù)字的,直接將數(shù)字(unicode)轉(zhuǎn)為char
遇到第二情況,中間是字符,只能查映射表了,從映射表中找到字符對應(yīng)的數(shù)字再轉(zhuǎn)換為char 看看代碼就一目了然了

看看HTML40如何定義的

復(fù)制代碼
代碼如下:
static {
HTML40 = new Entities();
fillWithHtml40Entities(HTML40);
}
static void fillWithHtml40Entities(Entities entities) {
entities.addEntities(BASIC_ARRAY);
entities.addEntities(ISO8859_1_ARRAY);
entities.addEntities(HTML40_ARRAY);
}

再看看BASIC_ARRAY、ISO8859_1_ARRAY、HTML40_ARRAY 分別是什么

BASIC_ARRAY

復(fù)制代碼
代碼如下:
private static final String[][] BASIC_ARRAY = {{"quot", "34"}, // " - double-quote
{"amp", "38"}, // & - ampersand
{"lt", "60"}, // < - less-than
{"gt", "62"}, // > - greater-than
};

ISO8859_1_ARRAY

復(fù)制代碼
代碼如下:
static final String[][] ISO8859_1_ARRAY = {{"nbsp", "160"}, // non-breaking space
{"iexcl", "161"}, // inverted exclamation mark
{"cent", "162"}, // cent sign
{"pound", "163"}, // pound sign
{"curren", "164"}, // currency sign
{"yen", "165"}, // yen sign = yuan sign
{"brvbar", "166"}, // broken bar = broken vertical bar
{"sect", "167"}, // section sign
{"uml", "168"}, // diaeresis = spacing diaeresis
{"copy", "169"}, // � - copyright sign
{"ordf", "170"}, // feminine ordinal indicator
{"laquo", "171"}, // left-pointing double angle quotation mark = left pointing guillemet
{"not", "172"}, // not sign
{"shy", "173"}, // soft hyphen = discretionary hyphen
{"reg", "174"}, // � - registered trademark sign
{"macr", "175"}, // macron = spacing macron = overline = APL overbar
{"deg", "176"}, // degree sign
{"plusmn", "177"}, // plus-minus sign = plus-or-minus sign
{"sup2", "178"}, // superscript two = superscript digit two = squared
{"sup3", "179"}, // superscript three = superscript digit three = cubed
{"acute", "180"}, // acute accent = spacing acute
{"micro", "181"}, // micro sign
{"para", "182"}, // pilcrow sign = paragraph sign
{"middot", "183"}, // middle dot = Georgian comma = Greek middle dot
{"cedil", "184"}, // cedilla = spacing cedilla
{"sup1", "185"}, // superscript one = superscript digit one
{"ordm", "186"}, // masculine ordinal indicator
{"raquo", "187"}, // right-pointing double angle quotation mark = right pointing guillemet
{"frac14", "188"}, // vulgar fraction one quarter = fraction one quarter
{"frac12", "189"}, // vulgar fraction one half = fraction one half
{"frac34", "190"}, // vulgar fraction three quarters = fraction three quarters
{"iquest", "191"}, // inverted question mark = turned question mark
{"Agrave", "192"}, // � - uppercase A, grave accent
{"Aacute", "193"}, // � - uppercase A, acute accent
{"Acirc", "194"}, // � - uppercase A, circumflex accent
{"Atilde", "195"}, // � - uppercase A, tilde
{"Auml", "196"}, // � - uppercase A, umlaut
{"Aring", "197"}, // � - uppercase A, ring
{"AElig", "198"}, // � - uppercase AE
{"Ccedil", "199"}, // � - uppercase C, cedilla
{"Egrave", "200"}, // � - uppercase E, grave accent
{"Eacute", "201"}, // � - uppercase E, acute accent
{"Ecirc", "202"}, // � - uppercase E, circumflex accent
{"Euml", "203"}, // � - uppercase E, umlaut
{"Igrave", "204"}, // � - uppercase I, grave accent
{"Iacute", "205"}, // � - uppercase I, acute accent
{"Icirc", "206"}, // � - uppercase I, circumflex accent
{"Iuml", "207"}, // � - uppercase I, umlaut
{"ETH", "208"}, // � - uppercase Eth, Icelandic
{"Ntilde", "209"}, // � - uppercase N, tilde
{"Ograve", "210"}, // � - uppercase O, grave accent
{"Oacute", "211"}, // � - uppercase O, acute accent
{"Ocirc", "212"}, // � - uppercase O, circumflex accent
{"Otilde", "213"}, // � - uppercase O, tilde
{"Ouml", "214"}, // � - uppercase O, umlaut
{"times", "215"}, // multiplication sign
{"Oslash", "216"}, // � - uppercase O, slash
{"Ugrave", "217"}, // � - uppercase U, grave accent
{"Uacute", "218"}, // � - uppercase U, acute accent
{"Ucirc", "219"}, // � - uppercase U, circumflex accent
{"Uuml", "220"}, // � - uppercase U, umlaut
{"Yacute", "221"}, // � - uppercase Y, acute accent
{"THORN", "222"}, // � - uppercase THORN, Icelandic
{"szlig", "223"}, // � - lowercase sharps, German
{"agrave", "224"}, // � - lowercase a, grave accent
{"aacute", "225"}, // � - lowercase a, acute accent
{"acirc", "226"}, // � - lowercase a, circumflex accent
{"atilde", "227"}, // � - lowercase a, tilde
{"auml", "228"}, // � - lowercase a, umlaut
{"aring", "229"}, // � - lowercase a, ring
{"aelig", "230"}, // � - lowercase ae
{"ccedil", "231"}, // � - lowercase c, cedilla
{"egrave", "232"}, // � - lowercase e, grave accent
{"eacute", "233"}, // � - lowercase e, acute accent
{"ecirc", "234"}, // � - lowercase e, circumflex accent
{"euml", "235"}, // � - lowercase e, umlaut
{"igrave", "236"}, // � - lowercase i, grave accent
{"iacute", "237"}, // � - lowercase i, acute accent
{"icirc", "238"}, // � - lowercase i, circumflex accent
{"iuml", "239"}, // � - lowercase i, umlaut
{"eth", "240"}, // � - lowercase eth, Icelandic
{"ntilde", "241"}, // � - lowercase n, tilde
{"ograve", "242"}, // � - lowercase o, grave accent
{"oacute", "243"}, // � - lowercase o, acute accent
{"ocirc", "244"}, // � - lowercase o, circumflex accent
{"otilde", "245"}, // � - lowercase o, tilde
{"ouml", "246"}, // � - lowercase o, umlaut
{"divide", "247"}, // division sign
{"oslash", "248"}, // � - lowercase o, slash
{"ugrave", "249"}, // � - lowercase u, grave accent
{"uacute", "250"}, // � - lowercase u, acute accent
{"ucirc", "251"}, // � - lowercase u, circumflex accent
{"uuml", "252"}, // � - lowercase u, umlaut
{"yacute", "253"}, // � - lowercase y, acute accent
{"thorn", "254"}, // � - lowercase thorn, Icelandic
{"yuml", "255"}, // � - lowercase y, umlaut
};
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 闵行区| 肇庆市| 肇州县| 册亨县| 崇明县| 保亭| 离岛区| 乌鲁木齐县| 永寿县| 洛南县| 顺昌县| 汪清县| 马公市| 东乌珠穆沁旗| 顺昌县| 太康县| 青铜峡市| 桐柏县| 夏邑县| 滁州市| 寿宁县| 乾安县| 太湖县| 岳普湖县| 天津市| 扎赉特旗| 海安县| 华池县| 托里县| 苍溪县| 永康市| 桐庐县| 武鸣县| 乌什县| 克山县| 深圳市| 墨脱县| 蕉岭县| 句容市| 平安县| 武宁县|