PHP get_html_translation_table() 函数


实例

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

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <?php
  5. print_r (get_html_translation_table()); // HTML_SPECIALCHARS 为默认
  6. ?>
  7. </body>
  8. </html>

定义和用法

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

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


语法

  1. 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 5character-set 参数的默认值改为 UTF-8。
PHP 5.4

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

  • ENT_HTML401
  • ENT_HTML5
  • ENT_XML1
  • ENT_XHTML
PHP 5.3.4新增了 character-set 参数。

更多实例

实例

HTML_SPECIALCHARS 的翻译表:

  1. <?php
  2. print_r (get_html_translation_table(HTML_SPECIALCHARS));
  3. ?>

显示字符和实体名:

  1. Array
  2. (
  3. ["] => "
  4. [&] => &amp;
  5. [<] => <
  6. [>] => >
  7. )
例子 2

HTML_ENTITIES 的翻译表:

  1. <?php
  2. print_r (get_html_translation_table(HTML_ENTITIES));
  3. ?>

显示字符和实体名:

  1. Array
  2. (
  3. ["] => "
  4. [&] => &amp;
  5. [<] => <
  6. [>] => >
  7. [ ] => &nbsp;
  8. [?] => &iexcl;
  9. [?] => &cent;
  10. [?] => &pound;
  11. [?] => &curren;
  12. [?] => &yen;
  13. [?] => &brvbar;
  14. [?] => &sect;
  15. [?] => &uml;
  16. [?] => &copy;
  17. [?] => &ordf;
  18. [?] => &laquo;
  19. [?] => &not;
  20. [?] => &shy;
  21. [?] => &reg;
  22. [?] => &macr;
  23. [?] => &deg;
  24. [?] => &plusmn;
  25. [?] => &sup2;
  26. [?] => &sup3;
  27. [?] => &acute;
  28. [?] => &micro;
  29. [?] => &para;
  30. [?] => &middot;
  31. [?] => &cedil;
  32. [?] => &sup1;
  33. [?] => &ordm;
  34. [?] => &raquo;
  35. [?] => &frac14;
  36. [?] => &frac12;
  37. [?] => &frac34;
  38. [?] => &iquest;
  39. [?] => &Agrave;
  40. [?] => &Aacute;
  41. [?] => &Acirc;
  42. [?] => &Atilde;
  43. [?] => &Auml;
  44. [?] => &Aring;
  45. [?] => &AElig;
  46. [?] => &Ccedil;
  47. [?] => &Egrave;
  48. [?] => &Eacute;
  49. [?] => &Ecirc;
  50. [?] => &Euml;
  51. [?] => &Igrave;
  52. [?] => &Iacute;
  53. [?] => &Icirc;
  54. [?] => &Iuml;
  55. [?] => &ETH;
  56. [?] => &Ntilde;
  57. [?] => &Ograve;
  58. [?] => &Oacute;
  59. [?] => &Ocirc;
  60. [?] => &Otilde;
  61. [?] => &Ouml;
  62. [?] => &times;
  63. [?] => &Oslash;
  64. [?] => &Ugrave;
  65. [?] => &Uacute;
  66. [?] => &Ucirc;
  67. [?] => &Uuml;
  68. [?] => &Yacute;
  69. [?] => &THORN;
  70. [?] => &szlig;
  71. [?] => &agrave;
  72. [?] => &aacute;
  73. [?] => &acirc;
  74. [?] => &atilde;
  75. [?] => &auml;
  76. [?] => &aring;
  77. [?] => &aelig;
  78. [?] => &ccedil;
  79. [?] => &egrave;
  80. [?] => &eacute;
  81. [?] => &ecirc;
  82. [?] => &euml;
  83. [?] => &igrave;
  84. [?] => &iacute;
  85. [?] => &icirc;
  86. [?] => &iuml;
  87. [?] => &eth;
  88. [?] => &ntilde;
  89. [?] => &ograve;
  90. [?] => &oacute;
  91. [?] => &ocirc;
  92. [?] => &otilde;
  93. [?] => &ouml;
  94. [?] => &divide;
  95. [?] => &oslash;
  96. [?] => &ugrave;
  97. [?] => &uacute;
  98. [?] => &ucirc;
  99. [?] => &uuml;
  100. [?] => &yacute;
  101. [?] => &thorn;
  102. [?] => &yuml;
  103. [?] => &OElig;
  104. [?] => &oelig;
  105. [?] => &Scaron;
  106. [?] => &scaron;
  107. [?] => &Yuml;
  108. [?] => &fnof;
  109. [?] => &circ;
  110. [?] => &tilde;
  111. [Α] => &Alpha;
  112. [Β] => &Beta;
  113. [Γ] => &Gamma;
  114. [Δ] => &Delta;
  115. [Ε] => &Epsilon;
  116. [Ζ] => &Zeta;
  117. [Η] => &Eta;
  118. [Θ] => &Theta;
  119. [Ι] => &Iota;
  120. [Κ] => &Kappa;
  121. [Λ] => &Lambda;
  122. [Μ] => &Mu;
  123. [Ν] => &Nu;
  124. [Ξ] => &Xi;
  125. [Ο] => &Omicron;
  126. [Π] => &Pi;
  127. [Ρ] => &Rho;
  128. [Σ] => &Sigma;
  129. [Τ] => &Tau;
  130. [Υ] => &Upsilon;
  131. [Φ] => &Phi;
  132. [Χ] => &Chi;
  133. [Ψ] => &Psi;
  134. [Ω] => &Omega;
  135. [α] => &alpha;
  136. [β] => &beta;
  137. [γ] => &gamma;
  138. [δ] => &delta;
  139. [ε] => &epsilon;
  140. [ζ] => &zeta;
  141. [η] => &eta;
  142. [θ] => &theta;
  143. [ι] => &iota;
  144. [κ] => &kappa;
  145. [λ] => &lambda;
  146. [μ] => &mu;
  147. [ν] => &nu;
  148. [ξ] => &xi;
  149. [ο] => &omicron;
  150. [π] => &pi;
  151. [ρ] => &rho;
  152. [?] => &sigmaf;
  153. [σ] => &sigma;
  154. [τ] => &tau;
  155. [υ] => &upsilon;
  156. [φ] => &phi;
  157. [χ] => &chi;
  158. [ψ] => &psi;
  159. [ω] => &omega;
  160. [?] => &thetasym;
  161. [?] => &upsih;
  162. [?] => &piv;
  163. [?] => &ensp;
  164. [?] => &emsp;
  165. [?] => &thinsp;
  166. [?] => &zwnj;
  167. [?] => &zwj;
  168. [?] => &lrm;
  169. [?] => &rlm;
  170. [?] => &ndash;
  171. [?] => &mdash;
  172. [?] => &lsquo;
  173. [?] => &rsquo;
  174. [?] => &sbquo;
  175. [?] => &ldquo;
  176. [?] => &rdquo;
  177. [?] => &bdquo;
  178. [?] => &dagger;
  179. [?] => &Dagger;
  180. [?] => &bull;
  181. [?] => &hellip;
  182. [?] => &permil;
  183. [′] => &prime;
  184. [″] => &Prime;
  185. [?] => &lsaquo;
  186. [?] => &rsaquo;
  187. [ ̄] => &oline;
  188. [?] => &frasl;
  189. [?] => &euro;
  190. [?] => &image;
  191. [?] => &weierp;
  192. [?] => &real;
  193. [?] => &trade;
  194. [?] => &alefsym;
  195. [←] => &larr;
  196. [↑] => &uarr;
  197. [→] => &rarr;
  198. [↓] => &darr;
  199. [?] => &harr;
  200. [?] => &crarr;
  201. [?] => &lArr;
  202. [?] => &uArr;
  203. [?] => &rArr;
  204. [?] => &dArr;
  205. [?] => &hArr;
  206. [?] => &forall;
  207. [?] => &part;
  208. [?] => &exist;
  209. [?] => &empty;
  210. [?] => &nabla;
  211. [∈] => &isin;
  212. [?] => &notin;
  213. [?] => &ni;
  214. [∏] => &prod;
  215. [∑] => &sum;
  216. [?] => &minus;
  217. [?] => &lowast;
  218. [√] => &radic;
  219. [∝] => &prop;
  220. [∞] => &infin;
  221. [∠] => &ang;
  222. [∧] => &and;
  223. [∨] => &or;
  224. [∩] => &cap;
  225. [∪] => &cup;
  226. [∫] => &int;
  227. [∴] => &there4;
  228. [~] => &sim;
  229. [?] => &cong;
  230. [≈] => &asymp;
  231. [≠] => &ne;
  232. [≡] => &equiv;
  233. [≤] => &le;
  234. [≥] => &ge;
  235. [?] => &sub;
  236. [?] => &sup;
  237. [?] => &nsub;
  238. [?] => &sube;
  239. [?] => &supe;
  240. [⊕] => &oplus;
  241. [?] => &otimes;
  242. [⊥] => &perp;
  243. [?] => &sdot;
  244. [?] => &lceil;
  245. [?] => &rceil;
  246. [?] => &lfloor;
  247. [?] => &rfloor;
  248. [?] => &lang;
  249. [?] => &rang;
  250. [?] => &loz;
  251. [?] => &spades;
  252. [?] => &clubs;
  253. [?] => &hearts;
  254. [?] => &diams;
  255. )

分类导航