首頁 web前端 html教學 html的轉義字元怎麼透過程式碼識別

html的轉義字元怎麼透過程式碼識別

Feb 09, 2018 am 10:05 AM
html 怎樣 透過

這次帶給大家html的轉義字元怎麼透過程式碼識別,html的轉義字元透過程式碼識別的注意事項有哪些,以下就是實戰案例,一起來看一下。

偶爾會在資料中看到諸如' 這樣的字符,特徵如下
以開頭,中間是一串數字,以;結尾
以&開頭,中間一串字符,以;結尾
例如最常見的 或等價的 
瀏覽器遇到這些轉義符,會轉義回來,但如何通過代碼識別? org.apache.commons.lang.StringEscapeUtils.unescapeHtml提供了很好的說明
遇到上面的第一種情況,中間是數字的,直接將數字(unicode)轉為char
遇到第二情況,中間是字符,只能查映射表了,從映射表中找到字符對應的數字再轉換為char 看看代碼就一目了然了
看看HTML40如何定義的 

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 

private static final String[][] BASIC_ARRAY = {{"quot", "34"}, // " - double-quote 
{"amp", "38"}, // & - ampersand 
{"lt", "60"}, // < - less-than 
{"gt", "62"}, // > - greater-than 
};
登入後複製

ISO8859_1_ARRAY

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 
};
登入後複製


ML40_ARRAY#ML40_ARRAY

##從前面可以看到轉義字元中間的那段數字是unicode,那麼這個轉移字元可以隨便建構了,不限於上面的定義,例如中的unicode是20013,那麼建構一個轉移字元 20013;,經過瀏覽器的渲染就變回中了,雖然不必這麼繞為了顯示一個字符,但如果在一些不方便傳輸

特殊字符
的場景就可以派上用途了

相信看了這些案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章! 相關閱讀:

怎麼讓textarea文字域寬度和高度width及height自動適應

html超級連結a的click事件之後跳到href所指向的位址

#

以上是html的轉義字元怎麼透過程式碼識別的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1655
14
CakePHP 教程
1414
52
Laravel 教程
1307
25
PHP教程
1253
29
C# 教程
1227
24
HTML 中的表格邊框 HTML 中的表格邊框 Sep 04, 2024 pm 04:49 PM

HTML 表格邊框指南。在這裡,我們以 HTML 中的表格邊框為例,討論定義表格邊框的多種方法。

HTML 中的巢狀表 HTML 中的巢狀表 Sep 04, 2024 pm 04:49 PM

這是 HTML 中巢狀表的指南。這裡我們討論如何在表中建立表格以及對應的範例。

HTML 左邊距 HTML 左邊距 Sep 04, 2024 pm 04:48 PM

HTML 左邊距指南。在這裡,我們討論 HTML margin-left 的簡要概述及其範例及其程式碼實作。

HTML 表格佈局 HTML 表格佈局 Sep 04, 2024 pm 04:54 PM

HTML 表格佈局指南。在這裡,我們詳細討論 HTML 表格佈局的值以及範例和輸出。

HTML 輸入佔位符 HTML 輸入佔位符 Sep 04, 2024 pm 04:54 PM

HTML 輸入佔位符指南。在這裡,我們討論 HTML 輸入佔位符的範例以及程式碼和輸出。

HTML 有序列表 HTML 有序列表 Sep 04, 2024 pm 04:43 PM

HTML 有序列表指南。在這裡我們也分別討論了 HTML 有序列表和類型的介紹以及它們的範例

HTML onclick 按鈕 HTML onclick 按鈕 Sep 04, 2024 pm 04:49 PM

HTML onclick 按鈕指南。這裡我們分別討論它們的介紹、工作原理、範例以及各個事件中的onclick事件。

在 HTML 中移動文字 在 HTML 中移動文字 Sep 04, 2024 pm 04:45 PM

HTML 中的文字移動指南。在這裡我們討論一下marquee標籤如何使用語法和實作範例。

See all articles