Latest web development tutorials

PHP get_html_translation_table () function

PHP String Reference PHP String Reference

Examples

Output translation table used by htmlspecialchars function:

<?php
print_r (get_html_translation_table()); // HTML_SPECIALCHARS is default.
?>

Running instance »

Definition and Usage

get_html_translation_table () function returns the htmlentities () and htmlspecialchars () the translation table used by the function.

Tip: Some characters can be encoded according to a number of ways.get_html_translation_table () function returns the most common encoding.


grammar

get_html_translation_table( function,flags,character-set )

参数 描述
function 可选。规定返回哪个翻译表。

可能的值:

  • HTML_SPECIALCHARS - 默认。翻译某些需要 URL 编码的字符,以便正确地显示在 HTML 页面上。
  • HTML_ENTITIES - 翻译所有需要 URL 编码的字符,以便正确地显示在 HTML 页面上。
flags 可选。规定翻译表将包含哪种引号以及翻译表用于哪种文档类型。

可用的引号类型:

  • ENT_COMPAT - 默认。翻译表包含双引号实体,不包含单引号实体。
  • ENT_QUOTES - 翻译表包含双引号实体和单引号实体。
  • ENT_NOQUOTES - 翻译表不包含双引号实体和单引号实体。

规定翻译表适用的文档类型的附加 flags:

  • ENT_HTML401 - 默认。HTML 4.01 的翻译表。
  • ENT_HTML5 - HTML 5 的翻译表。
  • ENT_XML1 - XML 1 的翻译表。
  • ENT_XHTML - XHTML 的翻译表。
character-set 可选。一个规定了要使用的字符集的字符串。

允许的值:

  • UTF-8 - 默认。ASCII 兼容多字节的 8 位 Unicode
  • ISO-8859-1 - 西欧
  • ISO-8859-15 - 西欧(加入欧元符号 + ISO-8859-1 中丢失的法语和芬兰语字母)
  • cp866 - DOS 专用 Cyrillic 字符集
  • cp1251 - Windows 专用 Cyrillic 字符集
  • cp1252 - Windows 专用西欧字符集
  • KOI8-R - 俄语
  • BIG5 - 繁体中文,主要在台湾使用
  • GB2312 - 简体中文,国家标准字符集
  • BIG5-HKSCS - 带香港扩展的 Big5
  • Shift_JIS - 日语
  • EUC-JP - 日语
  • MacRoman - Mac 操作系统使用的字符集

注释:在 PHP 5.4 之前的版本,无法被识别的字符集将被忽略并由 ISO-8859-1 替代。自 PHP 5.4 起,无法被识别的字符集将被忽略并由 UTF-8 替代。

technical details

return value: Returns an array of translation table original character as a key entity as keys.
PHP version: 4+
Update log: In PHP 5, default value character-set parameters to UTF-8.

In PHP 5.4, add a translation table for specifying additional flags applicable document type: ENT_HTML401, ENT_HTML5, ENT_XML1 and ENT_XHTML.

In PHP 5.3.4, add the character-set parameters.


More examples

Examples

HTML_SPECIALCHARS translation table:

<?php
print_r (get_html_translation_table(HTML_SPECIALCHARS));
?>

Displaying character and entity name:

Array
(
["] => &quot;
[&] => &amp;
[<] => &lt;
[>] => &gt;
)



Example 2

HTML_ENTITIES translation table:

<?php
print_r (get_html_translation_table(HTML_ENTITIES));
?>

Display characters and their corresponding entity name:

Array
(
  ["] => &quot;
  [&] => &amp;
  [<] => &lt;
  [>] => &gt;
  [ ] => &nbsp;
  [] => &iexcl;
  [¢] => &cent;
  [£] => &pound;
  [] => &curren;
  [¥] => &yen;
  [¦] => &brvbar;
  [§] => &sect;
  [¨] => &uml;
  [©] => &copy;
  [ª] => &ordf;
  [«] => &laquo;
  [] => &not;
  [­] => &shy;
  [®] => &reg;
  [¯] => &macr;
  [°] => &deg;
  [±] => &plusmn;
  [²] => &sup2;
  [³] => &sup3;
  [] => &acute;
  [µ] => &micro;
  [] => &para;
  [·] => &middot;
  [.] => &cedil;
  [ª] => &sup1;
  [] => &ordm;
  [»] => &raquo;
  [1/4] => &frac14;
  [1/2] => &frac12;
  [3/4] => &frac34;
  [] => &iquest;
  [À] => &Agrave;
  [Á] => &Aacute;
  [Â] => &Acirc;
  [Ã] => &Atilde;
  [Ä] => &Auml;
  [Å] => &Aring;
  [Æ] => &AElig;
  [C] => &Ccedil;
  [E] => &Egrave;
  [E] => &Eacute;
  [E] => &Ecirc;
  [E] => &Euml;
  [I] => &Igrave;
  [I] => &Iacute;
  [I] => &Icirc;
  [I] => &Iuml;
  [Ð] => &ETH;
  [Ñ] => &Ntilde;
  [O] => &Ograve;
  [O] => &Oacute;
  [O] => &Ocirc;
  [O] => &Otilde;
  [O] => &Ouml;
  [×] => &times;
  [Ø] => &Oslash;
  [U] => &Ugrave;
  [U] => &Uacute;
  [U] => &Ucirc;
  [U] => &Uuml;
  [Y] => &Yacute;
  [Þ] => &THORN;
  [ß] => &szlig;
  [a] => &agrave;
  [a] => &aacute;
  [a] => &acirc;
  [a] => &atilde;
  [a] => &auml;
  [a] => &aring;
  [a] => &aelig;
  [c] => &ccedil;
  [e] => &egrave;
  [e] => &eacute;
  [e] => &ecirc;
  [e] => &euml;
  [i] => &igrave;
  [i] => &iacute;
  [i] => &icirc;
  [i] => &iuml;
  [] => &eth;
  [n] => &ntilde;
  [o] => &ograve;
  [o] => &oacute;
  [o] => &ocirc;
  [o] => &otilde;
  [o] => &ouml;
  [÷] => &divide;
  [] => &oslash;
  [u] => &ugrave;
  [u] => &uacute;
  [u] => &ucirc;
  [u] => &uuml;
  [y] => &yacute;
  [þ] => &thorn;
  [y] => &yuml;
  [Œ] => &OElig;
  [œ] => &oelig;
  [Š] => &Scaron;
  [š] => &scaron;
  [Ÿ] => &Yuml;
  [ƒ] => &fnof;
  [ˆ] => &circ;
  [˜] => &tilde;
  [Α] => &Alpha;
  [Β] => &Beta;
  [Γ] => &Gamma;
  [Δ] => &Delta;
  [Ε] => &Epsilon;
  [Ζ] => &Zeta;
  [Η] => &Eta;
  [Θ] => &Theta;
  [Ι] => &Iota;
  [Κ] => &Kappa;
  [Λ] => &Lambda;
  [Μ] => &Mu;
  [Ν] => &Nu;
  [Ξ] => &Xi;
  [Ο] => &Omicron;
  [Π] => &Pi;
  [Ρ] => &Rho;
  [Σ] => &Sigma;
  [Τ] => &Tau;
  [Υ] => &Upsilon;
  [Φ] => &Phi;
  [Χ] => &Chi;
  [Ψ] => &Psi;
  [Ω] => &Omega;
  [α] => &alpha;
  [β] => &beta;
  [γ] => &gamma;
  [δ] => &delta;
  [ε] => &epsilon;
  [ζ] => &zeta;
  [η] => &eta;
  [θ] => &theta;
  [ι] => &iota;
  [κ] => &kappa;
  [λ] => &lambda;
  [μ] => &mu;
  [ν] => &nu;
  [ξ] => &xi;
  [ο] => &omicron;
  [π] => &pi;
  [ρ] => &rho;
  [ς] => &sigmaf;
  [σ] => &sigma;
  [τ] => &tau;
  [υ] => &upsilon;
  [φ] => &phi;
  [χ] => &chi;
  [ψ] => &psi;
  [ω] => &omega;
  [ϑ] => &thetasym;
  [ϒ] => &upsih;
  [ϖ] => &piv;
  [ ] => &ensp;
  [ ] => &emsp;
  [ ] => &thinsp;
  [‌] => &zwnj;
  [‍] => &zwj;
  [‎] => &lrm;
  [‏] => &rlm;
  [–] => &ndash;
  [—] => &mdash;
  ['] => &lsquo;
  ['] => &rsquo;
  [‚] => &sbquo;
  ["] => &ldquo;
  ["] => &rdquo;
  [„] => &bdquo;
  [†] => &dagger;
  [‡] => &Dagger;
  [•] => &bull;
  […] => &hellip;
  [‰] => &permil;
  [′] => &prime;
  [″] => &Prime;
  [‹] => &lsaquo;
  [›] => &rsaquo;
  [‾] => &oline;
  [⁄] => &frasl;
  [€] => &euro;
  [ℑ] => &image;
  [℘] => &weierp;
  [ℜ] => &real;
  [™] => &trade;
  [ℵ] => &alefsym;
  [←] => &larr;
  [↑] => &uarr;
  [→] => &rarr;
  [↓] => &darr;
  [↔] => &harr;
  [↵] => &crarr;
  [⇐] => &lArr;
  [⇑] => &uArr;
  [⇒] => &rArr;
  [⇓] => &dArr;
  [⇔] => &hArr;
  [∀] => &forall;
  [∂] => &part;
  [∃] => &exist;
  [∅] => &empty;
  [∇] => &nabla;
  [∈] => &isin;
  [∉] => &notin;
  [∋] => &ni;
  [∏] => &prod;
  [∑] => &sum;
  [−] => &minus;
  [∗] => &lowast;
  [√] => &radic;
  [∝] => &prop;
  [∞] => &infin;
  [∠] => &ang;
  [∧] => &and;
  [∨] => &or;
  [∩] => &cap;
  [∪] => &cup;
  [∫] => &int;
  [∴] => &there4;
  [∼] => &sim;
  [≅] => &cong;
  [≈] => &asymp;
  [≠] => &ne;
  [≡] => &equiv;
  [≤] => &le;
  [≥] => &ge;
  [⊂] => &sub;
  [⊃] => &sup;
  [⊄] => &nsub;
  [⊆] => &sube;
  [⊇] => &supe;
  [⊕] => &oplus;
  [⊗] => &otimes;
  [⊥] => &perp;
  [⋅] => &sdot;
  [⌈] => &lceil;
  [⌉] => &rceil;
  [⌊] => &lfloor;
  [⌋] => &rfloor;
  [〈] => &lang;
  [〉] => &rang;
  [◊] => &loz;
  [♠] => &spades;
  [♣] => &clubs;
  [♥] => &hearts;
  [♦] => &diams;
)



PHP String Reference PHP String Reference