PHP String get_html_translation_table() Function

The get_html_translation_table() function in PHP is used to return the translation table used by the htmlentities() and htmlspecialchars() functions.

Syntax

get_html_translation_table ([ int $table = HTML_SPECIALCHARS [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = "UTF-8" ]]] )

Parameter

table (optional)- This parameter specifies which translation table to return. It either returns HTML_ENTITIES or HTML_SPECIALCHARS.

flags (optional)- This parameter specifies which quotes the table will contain and which document type the table is for. The available flag constants are as follows:

  • ENT_COMPAT- Table contains entities only for double-quotes
  • ENT_QUOTES- The Table contains entities for both double and single quotes
  • ENT_NOQUOTES- Table contains entities neither for single quotes nor for double quotes.
  • ENT_HTML401- Table specifically for HTML 4.01.
  • ENT_XML1- Table for XML 1.
  • ENT_XHTML- Table for XHTML.
  • ENT_HTML5- Table for HTML 5.

Character-set (optional)- It represents a string that specifies which character-set to use. The following character set are supported:

  • UTF-8 - Default. ASCII compatible multi-byte 8-bit Unicode
  • ISO-8859-1 - Western European
  • ISO-8859-15 - Western European (adds the Euro sign + French and Finnish letters missing in ISO-8859-1)
  • cp866 - DOS-specific Cyrillic charset
  • cp1251 - Windows-specific Cyrillic charset
  • cp1252 - Windows specific charset for Western European
  • KOI8-R - Russian
  • BIG5 - Traditional Chinese, mainly used in Taiwan
  • GB2312 - Simplified Chinese, national standard character set
  • BIG5-HKSCS - Big5 with Hong Kong extensions
  • Shift_JIS - Japanese
  • EUC-JP - Japanese
  • MacRoman - Character-set that was used by Mac OS

Return

This function returns the translation table as an array, with the original characters as keys and entities as values.

Example 1

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

Output

Array
 (
     ["] => "
     [&] => & 
     [<] => <
     [>] => >
     [ ] =>  
     [¡] => ¡ 
     [¢] => ¢
     [£] => £
     [¤] => ¤
     [¥] => ¥ 
     [¦] => ¦
     [§] => §
     [¨] => ¨
     [©] => © 
     [ª] => ª
     [«] => «
     [¬] => ¬
     [­] => ­
     [®] => ®
     [¯] => ¯
     [°] => ° 
     [±] => ±
     [²] => ²
     [³] => ³
     [´] => ´
     [µ] => µ 
     [¶] => ¶
     [·] => ·
     [¸] => ¸
     [¹] => ¹
     [º] => º 
     [»] => »
     [¼] => ¼
     [½] => ½
     [¾] => ¾
     [¿] => ¿ 
     [À] => À
     [Á] => Á
     [Â] => Â
     [Ã] => Ã
     [Ä] => Ä
     [Å] => Å
     [Æ] => Æ 
     [Ç] => Ç
     [È] => È
     [É] => É
     [Ê] => Ê
     [Ë] => Ë
     [Ì] => Ì 
     [Í] => Í
     [Î] => Î
     [Ï] => Ï
     [Ð] => Ð
     [Ñ] => Ñ
     [Ò] => Ò
     [Ó] => Ó 
     [Ô] => Ô
     [Õ] => Õ
     [Ö] => Ö
     [×] => ×
     [Ø] => Ø
     [Ù] => Ù
     [Ú] => Ú
     [Û] => Û 
     [Ü] => Ü
     [Ý] => Ý
     [Þ] => Þ
     [ß] => ß
     [à] => à
     [á] => á
     [â] => â 
     [ã] => ã
     [ä] => ä
     [å] => å
     [æ] => æ
     [ç] => ç
     [è] => è
     [é] => é
     [ê] => ê 
     [ë] => ë
     [ì] => ì
     [í] => í
     [î] => î
     [ï] => ï
     [ð] => ð
     [ñ] => ñ 
     [ò] => ò
     [ó] => ó
     [ô] => ô
     [õ] => õ
     [ö] => ö
     [÷] => ÷
     [ø] => ø
     [ù] => ù 
     [ú] => ú
     [û] => û
     [ü] => ü
     [ý] => ý
     [þ] => þ
     [ÿ] => ÿ
     [Œ] => Œ 
     [œ] => œ
     [Š] => Š
     [š] => š
     [Ÿ] => Ÿ
     [ƒ] => ƒ
     [ˆ] => ˆ
     [˜] => ˜
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [–] => –
     [—] => —
     [‘] => ‘ 
     [’] => ’
     [‚] => ‚
     [“] => “
     [”] => ”
     [„] => „
     [†] => †
     [‡] => ‡
     [•] => • 
     […] => …
     [‰] => ‰
     [?] => ?
     [?] => ?
     [‹] => ‹
     [›] => ›
     [?] => ?
     [?] => ?
     [€] => € 
     [?] => ?
     [?] => ?
     [?] => ?
     [™] => ™
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => √
     [?] => ∝
     [?] => ∞
     [?] => ∠
     [?] => ∧
     [?] => ∨
     [?] => ∩
     [?] => ∪
     [?] => ∫
     [?] => ∴
     [?] => ∼
     [?] => ≅
     [?] => ≈
     [?] => ≠
     [?] => ≡
     [?] => ≤
     [?] => ≥
     [?] => ⊂
     [?] => ⊃
     [?] => ⊄
     [?] => ⊆
     [?] => ⊇
     [?] => ⊕
     [?] => ⊗
     [?] => ⊥
     [?] => ⋅
     [?] => ⌈
     [?] => ⌉
     [?] => ⌊ 

Example 2

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

Output

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

Example 3

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

Output

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