最新的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字符串參考