PHP get_html_translation_table() function

Example

Output the translation table used by the htmlspecialchars function:

<?php
print_r (get_html_translation_table()); // HTML_SPECIALCHARS is the default
?>

Running Example

Definition and Usage

The get_html_translation_table() function returns htmlentities() and htmlspecialchars() Translation table used by the function.

Tip:Some characters can be encoded in multiple ways. The get_html_translation_table() function returns the most common encoding.

Syntax

get_html_translation_table(function,flags,character-set)
Parameter Description
function

Optional. Specifies which translation table to return.

Possible values:

  • HTML_SPECIALCHARS - Default. Translates characters that need to be URL-encoded to display correctly on HTML pages
  • HTML_ENTITIES - Translates all characters that need to be URL-encoded to display correctly on HTML pages
flags

Optional. Specifies which quotes the translation table will include and the document type for which the translation table is used.

Available quote types:

  • ENT_COMPAT - Default. The translation table includes double quote entities but does not include single quote entities.
  • ENT_QUOTES - The translation table includes double quote entities and single quote entities.
  • ENT_NOQUOTES - The translation table does not include double quote entities and single quote entities.

Additional flags for specifying the document types applicable to the translation table:

  • ENT_HTML401 - Default. Translation table for HTML 4.01.
  • ENT_HTML5 - Translation table for HTML 5.
  • ENT_XML1 - Translation table for XML 1.
  • ENT_XHTML - Translation table for XHTML.
character-set

Optional. String value, specifying the character set to be used.

Allowed values:

  • UTF-8 - Default. ASCII-compatible 8-bit Unicode
  • ISO-8859-1 - Western Europe
  • ISO-8859-15 - Western Europe (includes euro symbols + French and Finnish letters missing in ISO-8859-1)
  • cp866 - Cyrillic character set for DOS
  • cp1251 - Cyrillic character set for Windows
  • cp1252 - West European character set for Windows
  • KOI8-R - Russian
  • BIG5 - Traditional Chinese, mainly used in Taiwan
  • GB2312 - Simplified Chinese, national standard character set
  • BIG5-HKSCS - Big5 with Hong Kong extension
  • Shift_JIS - Japanese
  • EUC-JP - Japanese
  • MacRoman - Character set used by the Mac operating system

Note:In versions of PHP prior to 5.4, unrecognized character sets are ignored and replaced by ISO-8859-1. Starting with PHP 5.4, unrecognized character sets are ignored and replaced by UTF-8.

Technical details

Return value: The translation table is returned in array form, with the original character as the key name and the entity as the key value.
PHP version: 4+

Update log:

Version Description
PHP 5 character-set The default value of the parameter has been changed to UTF-8.
PHP 5.4

Additional flags have been added to specify the document types applicable to the translation table:

  • ENT_HTML401
  • ENT_HTML5
  • ENT_XML1
  • ENT_XHTML
PHP 5.3.4 Added in character-set Parameter.

More examples

Example

HTML_SPECIALCHARS translation table:

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

Display characters and entity names:

Array
(
  ["] => "
  [&] => &
  [<] => <
  [>] => >
)

Example 2

HTML_ENTITIES translation table:

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

Display characters and entity names:

Array
(
  ["] => "
  [&] => &
  [<] => <
  [>] => >
  [ ] =>  
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ?
  [?] => ä
  [?] => å
  [?] => æ
  [?] => ç
  [?] => è
  [?] => é
  [?] => ê
  [?] => ë
  [?] => ì
  [?] => í
  [?] => î
  [?] => ï
  [?] => ð
  [?] => ñ
  [?] => ò
  [?] => ó
  [?] => ô
  [?] => õ
  [?] => ö
  [?] => ÷
  [?] => ø
  [?] => ù
  [?] => ú
  [?] => û
  [?] => ü
  [?] => ý
  [?] => þ
  [?] => ÿ
  [?] => Œ
  [?] => œ
  [?] => Š
  [?] => š
  [?] => Ÿ
  [?] => ƒ
  [?] => Â
  [?] => ˜
  [Α] => Α
  [Β] => Β
  [Γ] => Γ
  [Δ] => Δ
  [Ε] => Ε
  [Ζ] => Ζ
  [Η] => Η
  [Θ] => Θ
  [Ι] => Ι
  [Κ] => Κ
  [Λ] => Λ
  [Μ] => Μ
  [Ν] => Ν
  [Ξ] => Ξ
  [Ο] => Ο
  [Π] => Π
  [Ρ] => Ρ
  [Σ] => Σ
  [Τ] => Τ
  [Υ] => Υ
  [Φ] => Φ
  [Χ] => Χ
  [Ψ] => Ψ
  [Ω] => Ω
  [α] => α
  [β] => β
  [γ] => γ
  [δ] => δ
  [ε] => ε
  [ζ] => ζ
  [η] => η
  [θ] => θ
  [ι] => ι
  [κ] => κ
  [λ] => λ
  [μ] => μ
  [ν] => ν
  [ξ] => ξ
  [ο] => ο
  [π] => π
  [ρ] => ρ
  [?] => ς
  [σ] => σ
  [τ] => τ
  [υ] => υ
  [φ] => φ
  [χ] => χ
  [ψ] => ψ
  [ω] => ω
  [?] => ϑ
  [?] => ϒ
  [?] => ϖ
  [?] =>  
  [?] =>
  [?] =>  
  [?] => ‌
  [?] => ‍
  [?] => ‎
  [?] => ‏
  [?] => –
  [?] => —
  [?] => ‘
  [?] => ’
  [?] => ‚
  [?] => “
  [?] => ”
  [?] => „
  [?] => †
  [?] => ‡
  [?] => •
  [?] => …
  [?] => ‰
  [′] => ′
  [″] => ″
  [?] => ‹
  [?] => ›
  [ ̄] => ‾
  [?] => ⁄
  [?] => €
  [?] => ℑ
  [?] => ℘
  [?] => ℜ
  [?] => ™
  [?] => ℵ
  [←] => ←
  [↑] => ↑
  [→] => →
  [↓] => ↓
  [?] => ↔
  [?] => ↵
  [?] => ⇐
  [?] => ⇑
  [?] => ⇒
  [?] => ⇓
  [?] => ⇔
  [?] => ∀
  [?] => ∂
  [?] => ∃
  [?] => ∅
  [?] => ∇
  [∈] => ∈
  [?] => ∉
  [?] => ∋
  [∏] => ∏
  [∑] => ∑
  [?] => −
  [?] => ∗
  [√] => √
  [∝] => ∝
  [∞] => ∞
  [∠] => ∠
  [∧] => ∧
  [∨] => ∨
  [∩] => ∩
  [∪] => ∪
  [∫] => ∫
  [∴] => ∴
  [~] => ∼
  [?] => ≅
  [≈] => ≈
  [≠] => ≠
  [≡] => ≡
  [≤] => ≤
  [≥] => ≥
  [?] => ⊂
  [?] => ⊃
  [?] => ⊄
  [?] => ⊆
  [?] => ⊇
  [⊕] => ⊕
  [?] => ⊗
  [⊥] => ⊥
  [?] => ⋅
  [?] => ⌈
  [?] => ⌉
  [?] => ⌊
  [?] => ⌋
  [?] => ⟨
  [?] => ⟩
  [?] => ◊
  [?] => ♠
  [?] => ♣
  [?] => ♥
  [?] => ♦
)