PHP 教程

PHP get_html_translation_table() 函数

PHP String 参考手册 PHP String 参考手册

实例

输出 htmlspecialchars 函数使用的翻译表:

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

运行代码 >>

定义和用法

get_html_translation_table() 函数返回 htmlentities()htmlspecialchars() 函数使用的翻译表。

提示:一些字符可以按照若干种方式进行编码。get_html_translation_table() 函数返回最普通的编码。


语法

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 替代。

技术细节

返回值: 以数组形式返回翻译表,原始字符作为键名,实体作为键值。
PHP 版本: 4+
更新日志: 在 PHP 5 中,character-set 参数的默认值改为 UTF-8。

在 PHP 5.4 中,新增了用于规定翻译表适用的文档类型的附加 flags:ENT_HTML401、ENT_HTML5、ENT_XML1 和 ENT_XHTML。

在 PHP 5.3.4 中,新增了 character-set 参数。

更多实例

实例

HTML_SPECIALCHARS 的翻译表:

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

Displaying character and entity name:

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


实例 2

HTML_ENTITIES 的翻译表:

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

显示字符及其对应的实体名称:

Array
(
["] => &quot;
[&] => &amp;
[<] => &lt;
[>] => &gt;
[ ] => &nbsp;
[!] => &iexcl;
[c] => &cent;
[lb] => &pound;
[¤] => &curren;
[yen] => &yen;
[|] => &brvbar;
[§] => &sect;
[¨] => &uml;
[(c)] => &copy;
[a] => &ordf;
[<<] => &laquo;
[not] => &not;
[-] => &shy;
[(R)] => &reg;
[] => &macr;
[°] => &deg;
[±] => &plusmn;
[^2] => &sup2;
[^3] => &sup3;
['] => &acute;
[u] => &micro;
[P] => &para;
[·] => &middot;
[,] => &cedil;
[^1] => &sup1;
[o] => &ordm;
[>>] => &raquo;
[ 1/4 ] => &frac14;
[ 1/2 ] => &frac12;
[ 3/4 ] => &frac34;
[?] => &iquest;
[`A] => &Agrave;
['A] => &Aacute;
[^A] => &Acirc;
[~A] => &Atilde;
["A] => &Auml;
[A] => &Aring;
[AE] => &AElig;
[C] => &Ccedil;
[`E] => &Egrave;
['E] => &Eacute;
[^E] => &Ecirc;
["E] => &Euml;
[`I] => &Igrave;
['I] => &Iacute;
[^I] => &Icirc;
["I] => &Iuml;
[D] => &ETH;
[~N] => &Ntilde;
[`O] => &Ograve;
['O] => &Oacute;
[^O] => &Ocirc;
[~O] => &Otilde;
["O] => &Ouml;
[×] => &times;
[O] => &Oslash;
[`U] => &Ugrave;
['U] => &Uacute;
[^U] => &Ucirc;
["U] => &Uuml;
['Y] => &Yacute;
[Th] => &THORN;
[ss] => &szlig;
[à] => &agrave;
[á] => &aacute;
[^a] => &acirc;
[~a] => &atilde;
["a] => &auml;
[a] => &aring;
[ae] => &aelig;
[c] => &ccedil;
[è] => &egrave;
[é] => &eacute;
[ê] => &ecirc;
["e] => &euml;
[ì] => &igrave;
[í] => &iacute;
[^i] => &icirc;
["i] => &iuml;
[d] => &eth;
[~n] => &ntilde;
[ò] => &ograve;
[ó] => &oacute;
[^o] => &ocirc;
[~o] => &otilde;
["o] => &ouml;
[÷] => &divide;
[o] => &oslash;
[ù] => &ugrave;
[ú] => &uacute;
[^u] => &ucirc;
[ü] => &uuml;
['y] => &yacute;
[th] => &thorn;
["y] => &yuml;
[OE] => &OElig;
[oe] => &oelig;
[S] => &Scaron;
[s] => &scaron;
["Y] => &Yuml;
[f] => &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;
[o] => &bull;
[…] => &hellip;
[‰] => &permil;
[′] => &prime;
[″] => &Prime;
[<] => &lsaquo;
[>] => &rsaquo;
[] => &oline;
[/] => &frasl;
[EUR] => &euro;
[I] => &image;
[] => &weierp;
[R] => &real;
[TM] => &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 参考手册 PHP String 参考手册其他扩展

用微信扫一扫

收藏