字符串函数

PHP get_html_translation_table() 函数

主题:PHP 字符串参考上一页|下一页

说明

get_html_translation_table() 函数返回 htmlspecialchars()htmlentities() 函数使用的转换表。

下表总结了该函数的技术细节。

返回值: 将翻译表作为数组返回,原始字符作为键,实体作为值。
版本: PHP 4+

语法

get_html_translation_table() 函数的基本语法如下:

get_html_translation_table(table, flags, charset);

以下示例显示了 get_html_translation_table() 函数的作用。

<?php
// Getting translation table
$arr = get_html_translation_table(); // HTML_SPECIALCHARS is default
print_r($arr);
?>

上述示例的输出将如下所示(查看源代码):

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

注意:有些字符可以有多种编码方式,例如"(双引号)可以编码为 &quot;&#34;&#x22get_html_translation_table() 函数只返回 htmlspecialchars()htmlentities() 使用的形式。


参数

get_html_translation_table() 函数接受以下参数。

参数 说明
table 可选。 指定要返回的转换表。 HTML_ENTITIESHTML_SPECIALCHARS。 默认为 HTML_SPECIALCHARS
flags

可选。 指定表格将包含哪些引号以及表格所针对的文档类型。 您可以指定以下一个或多个标志。

处理引号的可用标志常量是:

  • ENT_COMPAT – 表将包含双引号的实体,但不包含单引号的实体。
  • ENT_QUOTES – 表将包含双引号和单引号的实体。
  • ENT_NOQUOTES – 表格不会同时包含单引号和双引号的实体。

用于指定文档类型的可用标志常量有:

  • ENT_HTML401 – HTML 4.01 的表格。
  • ENT_HTML5 – HTML 5 的表格。
  • ENT_XML1 – XML 1 的表。
  • ENT_XHTML – XHTML 表格。

此参数的默认值为 ENT_COMPAT | ENT_HTML401.

charset

可选。 指定要使用的字符集。 支持的字符集是:

  • UTF-8 –默认。 ASCII 兼容多字节 8 位 Unicode。
  • ISO-8859-1 –西欧,拉丁语 1。
  • ISO-8859-5 –很少使用西里尔字符集(拉丁文/西里尔文)。
  • ISO-8859-15 西欧,拉丁语 9。添加了 Latin-1 (ISO-8859-1) 中缺少的欧元符号、法语和芬兰语字母。
  • cp866 – DOS 特定的西里尔字符集。
  • cp1251 –特定于 Windows 的西里尔字符集。
  • cp1252 –西欧的 Windows 特定字符集。
  • KOI8-R –俄语。
  • BIG5 –繁体中文,主要用于台湾。
  • GB2312 –简体中文,国标字符集。
  • BIG5-HKSCS – Big5 带有香港扩展名,繁体中文。
  • Shift_JIS –日语。
  • EUC-JP –日语。
  • MacRoman – Mac OS 使用的字符集。

注意: 无法识别任何其他字符集。 在这种情况下将使用默认字符集 UTF-8 并生成警告。


更多示例

下面是更多示例,展示了 get_html_translation_table() 函数的实际工作原理:

以下示例返回 htmlentities() 函数使用的转换表。 查看示例输出的源代码(右键单击并选择查看页面源代码)以查看原始数据。

<?php
// 获取翻译表
$arr = get_html_translation_table(HTML_ENTITIES);
print_r($arr);
?>

上述示例的输出将如下所示(查看源代码):

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; )
Advertisements