PHP get_html_translation_table() 函数

实例

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

  1. <?php
  2. print_r (get_html_translation_table()); // HTML_SPECIALCHARS 为默认
  3. ?>

定义和用法

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 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 的翻译表:

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

    显示字符和实体名:

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

    例子 2

    HTML_ENTITIES 的翻译表:

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

    显示字符和实体名:

    1. Array
    2. (
    3. ["] => "
    4. [&] => &
    5. [<] => <
    6. [>] => >
    7. [ ] =>
    8. [?] =>
    9. [?] =>
    10. [?] =>
    11. [?] =>
    12. [?] =>
    13. [?] =>
    14. [?] =>
    15. [?] =>
    16. [?] =>
    17. [?] =>
    18. [?] =>
    19. [?] =>
    20. [?] =>
    21. [?] =>
    22. [?] =>
    23. [?] =>
    24. [?] =>
    25. [?] =>
    26. [?] =>
    27. [?] =>
    28. [?] =>
    29. [?] =>
    30. [?] =>
    31. [?] =>
    32. [?] => 鹿
    33. [?] =>
    34. [?] =>
    35. [?] =>
    36. [?] =>
    37. [?] =>
    38. [?] =>
    39. [?] =>
    40. [?] =>
    41. [?] =>
    42. [?] =>
    43. [?] =>
    44. [?] =>
    45. [?] =>
    46. [?] =>
    47. [?] =>
    48. [?] =>
    49. [?] =>
    50. [?] =>
    51. [?] =>
    52. [?] =>
    53. [?] =>
    54. [?] =>
    55. [?] =>
    56. [?] =>
    57. [?] =>
    58. [?] =>
    59. [?] =>
    60. [?] =>
    61. [?] =>
    62. [?] =>
    63. [?] =>
    64. [?] =>
    65. [?] =>
    66. [?] =>
    67. [?] =>
    68. [?] =>
    69. [?] =>
    70. [?] =>
    71. [?] =>
    72. [?] =>
    73. [?] =>
    74. [?] =>
    75. [?] =>
    76. [?] =>
    77. [?] =>
    78. [?] =>
    79. [?] =>
    80. [?] =>
    81. [?] =>
    82. [?] =>
    83. [?] =>
    84. [?] =>
    85. [?] =>
    86. [?] =>
    87. [?] =>
    88. [?] =>
    89. [?] =>
    90. [?] =>
    91. [?] =>
    92. [?] =>
    93. [?] =>
    94. [?] =>
    95. [?] =>
    96. [?] =>
    97. [?] =>
    98. [?] =>
    99. [?] =>
    100. [?] =>
    101. [?] =>
    102. [?] =>
    103. [?] =>
    104. [?] =>
    105. [?] =>
    106. [?] =>
    107. [?] =>
    108.  
    109. [?] =>
    110. [?] =>
    111. [?] =>
    112. [Α] =>
    113. [Β] =>
    114. [Γ] =>
    115. [Δ] =>
    116. [Ε] =>
    117. [Ζ] =>
    118. [Η] =>
    119. [Θ] =>
    120. [Ι] =>
    121. [Κ] =>
    122. [Λ] =>
    123. [Μ] =>
    124. [Ν] =>
    125. [Ξ] =>
    126. [Ο] =>
    127. [Π] =>
    128. [Ρ] =>
    129. [Σ] =>
    130. [Τ] =>
    131. [Υ] =>
    132. [Φ] =>
    133. [Χ] =>
    134. [Ψ] =>
    135. [Ω] =>
    136. [α] =>
    137. [β] =>
    138. [γ] =>
    139. [δ] =>
    140. [ε] =>
    141. [ζ] =>
    142. [η] =>
    143. [θ] =>
    144. [ι] =>
    145. [κ] =>
    146. [λ] =>
    147. [μ] =>
    148. [ν] =>
    149. [ξ] =>
    150. [ο] =>
    151. [π] =>
    152. [ρ] =>
    153. [?] =>
    154. [σ] =>
    155. [τ] =>
    156. [υ] =>
    157. [φ] =>
    158. [χ] =>
    159. [ψ] =>
    160. [ω] =>
    161. [?] =>
    162. [?] =>
    163. [?] =>
    164. [?] => 鈥�
    165. [?] => 鈥�
    166. [?] => 鈥�
    167. [?] => 鈥�
    168. [?] => 鈥�
    169. [?] => 鈥�
    170. [?] => 鈥�
    171. [?] => 鈥�
    172. [?] => 鈥�
    173. [?] => 鈥�
    174. [?] => 鈥�
    175. [?] => 鈥�
    176. [?] => 鈥�
    177. [?] => 鈥�
    178. [?] => 鈥�
    179. [?] => 鈥�
    180. [?] => 鈥�
    181. [?] => 鈥�
    182. [?] => 鈥�
    183. [?] => 鈥�
    184. [′] => 鈥�
    185. [″] => 鈥�
    186. [?] => 鈥�
    187. [?] => 鈥�
    188. [ ̄] => 鈥�
    189. [?] => 鈦�
    190. [?] => 鈧�
    191. [?] => 鈩�
    192. [?] => 鈩�
    193. [?] => 鈩�
    194. [?] => 鈩�
    195. [?] => 鈩�
    196. [←] => 鈫�
    197. [↑] => 鈫�
    198. [→] => 鈫�
    199. [↓] => 鈫�
    200. [?] => 鈫�
    201. [?] => 鈫�
    202. [?] => 鈬�
    203. [?] => 鈬�
    204. [?] => 鈬�
    205. [?] => 鈬�
    206. [?] => 鈬�
    207. [?] => 鈭�
    208. [?] => 鈭�
    209. [?] => 鈭�
    210. [?] => 鈭�
    211. [?] => 鈭�
    212. [∈] => 鈭�
    213. [?] => 鈭�
    214. [?] => 鈭�
    215. [∏] => 鈭�
    216. [∑] => 鈭�
    217. [?] => 鈭�
    218. [?] => 鈭�
    219. [√] => 鈭�
    220. [∝] => 鈭�
    221. [∞] => 鈭�
    222. [∠] => 鈭�
    223. [∧] => 鈭�
    224. [∨] => 鈭�
    225. [∩] => 鈭�
    226. [∪] => 鈭�
    227. [∫] => 鈭�
    228. [∴] => 鈭�
    229. [~] => 鈭�
    230. [?] => 鈮�
    231. [≈] => 鈮�
    232. [≠] => 鈮�
    233. [≡] => 鈮�
    234. [≤] => 鈮�
    235. [≥] => 鈮�
    236. [?] => 鈯�
    237. [?] => 鈯�
    238. [?] => 鈯�
    239. [?] => 鈯�
    240. [?] => 鈯�
    241. [⊕] => 鈯�
    242. [?] => 鈯�
    243. [⊥] => 鈯�
    244. [?] => 鈰�
    245. [?] => 鈱�
    246. [?] => 鈱�
    247. [?] => 鈱�
    248. [?] => 鈱�
    249. [?] => 鉄�
    250. [?] => 鉄�
    251. [?] => 鈼�
    252. [?] => 鈾�
    253. [?] => 鈾�
    254. [?] => 鈾�
    255. [?] => 鈾�
    256. )