コードを通じてHTMLのエスケープ文字を識別する方法
今回は、HTMLのエスケープ文字をコードで識別する方法を紹介します。 コードでHTMLのエスケープ文字を識別するための注意事項は何ですか。以下は実際のケースです。
データ中に ' のような文字が現れることがあります。その特徴は次のとおりです。真ん中の数字の列である で始まり、; で終わります。真ん中で;で終わります
たとえば、最も一般的な または同等のもの
ブラウザがこれらの
エスケープ文字
を検出すると、エスケープされて戻りますが、コードを通じてそれらを識別するにはどうすればよいですか? org.apache.commons.lang.StringEscapeUtils.unescapeHtml に詳しい説明があります上記の最初のケースに遭遇した場合、中央は数値であり、数値 (Unicode) を char に直接変換します 2 番目のケースに遭遇した場合、中央は文字の場合、マッピングテーブルから文字に対応する番号を見つけてそれをcharに変換するだけです。コードを見ると、BASIC_ARRAY
static { HTML40 = new Entities(); fillWithHtml40Entities(HTML40); } static void fillWithHtml40Entities(Entities entities) { entities.addEntities(BASIC_ARRAY); entities.addEntities(ISO8859_1_ARRAY); entities.addEntities(HTML40_ARRAY); }
がどのように定義されているかを見ることができます。 ISO8859_1_ARRAY
private static final String[][] BASIC_ARRAY = {{"quot", "34"}, // " - double-quote {"amp", "38"}, // & - ampersand {"lt", "60"}, // < - less-than {"gt", "62"}, // > - greater-than };
HTML40_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 };
再拡張
前から見てわかる通り、エスケープ文字の真ん中の数字はUnicodeなので、この転送文字は気軽に構築でき、上記の定義では、たとえば、 の Unicode が 20013 である場合、転送文字 中 を構築すると、ブラウザによってレンダリングされた後に「中」に戻りますが、この方法で表示する必要はありません。
特殊文字
これらの事例を読んだ後は、方法を習得したと思います。さらに興味深い情報については、php 中国語 Web サイトの他の関連記事に注目してください。 !
関連読書:
HTMLハイパーリンクaのクリックイベントの後、href
が指すアドレスにジャンプします
以上がコードを通じてHTMLのエスケープ文字を識別する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









HTML の表の境界線に関するガイド。ここでは、HTML でのテーブルの境界線の例を示しながら、テーブル境界線を定義する複数の方法について説明します。

これは、HTML でのネストされたテーブルのガイドです。ここでは、テーブル内にテーブルを作成する方法をそれぞれの例とともに説明します。

HTML マージン左のガイド。ここでは、HTML margin-left の概要とその例、およびそのコード実装について説明します。

HTML テーブル レイアウトのガイド。ここでは、HTML テーブル レイアウトの値と例および出力について詳しく説明します。

HTML 入力プレースホルダーのガイド。ここでは、コードと出力とともに HTML 入力プレースホルダーの例について説明します。

HTML でのテキストの移動に関するガイド。ここでは、概要、マーキー タグが構文でどのように機能するか、および実装例について説明します。

HTML オンクリック ボタンのガイド。ここでは、それらの紹介、動作、例、およびさまざまなイベントでの onclick イベントについてそれぞれ説明します。
