最新的Web开发教程
 

PHP get_html_translation_table() Function

<PHP字符串参考

打印在用htmlspecialchars函数使用的转换表:

<?php
print_r (get_html_translation_table()); // HTML_SPECIALCHARS is default.
?>
运行示例»

定义和用法

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

Tip:某些字符进行编码的几种方法。 所述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 - 表将不包含双和单引号实体

用于指定附加的标志,其DOCTYPE表为:

  • 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特定西里尔字符集
  • CP1251 - Windows专用字符集西里尔
  • CP1252 - 西欧Windows特定的字符集
  • KOI8-R - 俄语
  • BIG5 - 中国传统,主要用在台湾
  • GB2312 - 简体中国,国家标准字符集
  • BIG5-HKSCS - 中文与香港扩展
  • SHIFT_JIS - 日本
  • EUC-JP - 日本
  • 的MacRoman - 这是使用的Mac OS字符集

Note:无法识别的字符集将被忽略,并且在之前的PHP 5.4版本的ISO-8859-1代替。 作为PHP 5.4的,它将由UTF-8的取代被忽略。

技术细节

返回值: 返回翻译表作为一个数组,与原来的字符键和实体值
PHP版本: 4+
更新日志: 字符集参数的默认值被改变为UTF-8在PHP 5

用于指定附加的标志,其DOCTYPE表是用于; ENT_HTML401,ENT_HTML5,ENT_XML1和ENT_XHTML在PHP 5.4中添加

在PHP 5.3.4中加入的字符集参数

更多示例

表HTML_SPECIALCHARS:

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

显示字符和实体名称:

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



实施例2

表HTML_ENTITIES:

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

显示字符和实体名称:

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;
  [] => &frac14;
  [] => &frac12;
  [] => &frac34;
  [] => &iquest;
  [] => &Agrave;
  [] => &Aacute;
  [] => &Acirc;
  [] => &Atilde;
  [] => &Auml;
  [] => &Aring;
  [] => &AElig;
  [] => &Ccedil;
  [] => &Egrave;
  [] => &Eacute;
  [] => &Ecirc;
  [] => &Euml;
  [] => &Igrave;
  [] => &Iacute;
  [] => &Icirc;
  [] => &Iuml;
  [] => &ETH;
  [] => &Ntilde;
  [] => &Ograve;
  [] => &Oacute;
  [] => &Ocirc;
  [] => &Otilde;
  [] => &Ouml;
  [] => &times;
  [] => &Oslash;
  [] => &Ugrave;
  [] => &Uacute;
  [] => &Ucirc;
  [] => &Uuml;
  [] => &Yacute;
  [] => &THORN;
  [] => &szlig;
  [] => &agrave;
  [] => &aacute;
  [] => &acirc;
  [] => &atilde;
  [] => &auml;
  [] => &aring;
  [] => &aelig;
  [] => &ccedil;
  [] => &egrave;
  [] => &eacute;
  [] => &ecirc;
  [] => &euml;
  [] => &igrave;
  [] => &iacute;
  [] => &icirc;
  [] => &iuml;
  [] => &eth;
  [] => &ntilde;
  [] => &ograve;
  [] => &oacute;
  [] => &ocirc;
  [] => &otilde;
  [] => &ouml;
  [] => &divide;
  [] => &oslash;
  [] => &ugrave;
  [] => &uacute;
  [] => &ucirc;
  [] => &uuml;
  [] => &yacute;
  [] => &thorn;
  [] => &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字符串参考