Blog : PHP get_html_translation_table() Function

PHP get_html_translation_table() Function

--------------------------------------------------------------------------------
 Complete PHP String Reference
--------------------------------------------------------------------------------

Definition and Usage
The get_html_translation_table() function returns the translation table used by the htmlentities() and htmlspecialchars() functions.

Syntax
get_html_translation_table(function,quotestyle)  

Parameter Description
function Optional. Specifies which translation table to return. Default is HTML_SPECIALCHARS.
Possible values:

HTML_ENTITIES - Translates all characters that need URL-encoding to be shown properly on a HTML page
HTML_SPECIALCHARS - Translates some characters that need URL-encoding to be shown properly on a HTML page
 
quotestyle Optional. Defines how to encode single and double quotes. Default is ENT_COMPAT
Possible values:

ENT_COMPAT - Encodes double quotes, not single quotes
ENT_QUOTES - Encodes double and single quotes
ENT_NOQUOTES - Does not encode single or double quotes
 


--------------------------------------------------------------------------------

Tips and Notes
Tip: Some characters can be encoded several ways. The get_html_translation_table() function returns the most common encoding.


--------------------------------------------------------------------------------

Example
In this example we will show both translation tables.:

print_r (get_html_translation_table());
echo "
";
print_r (get_html_translation_table(HTML_ENTITIES));
?>  

The output of the code above will be:

Array
(
["] => " [<] => < [>] => > [&] => &
)
Array
(
[ ] =>  [¡] => ¡ [¢] => ¢ [£] => £
[¤] => ¤ [¥] => ¥ [¦] => ¦ [§] => §
[¨] => ¨ [©] => © [ª] => ª [«] => «
[¬] => ¬ [­] => ­ [®] => ® [¯] => ¯
[°] => ° [±] => ± [²] => ² [³] => ³
[´] => ´ [µ] => µ [¶] => ¶ [·] => ·
[¸] => ¸ [¹] => ¹ [º] => º [»] => »
[¼] => ¼ [½] => ½ [¾] => ¾ [¿] => ¿
[À] => À [Á] => Á [Â] => Â [Ã] => Ã
[Ä] => Ä [Å] => Å [Æ] => Æ [Ç] => Ç
[È] => È [É] => É [Ê] => Ê [Ë] => Ë
[Ì] => Ì [Í] => Í [Î] => Î [Ï] => Ï
[Ð] => Ð [Ñ] => Ñ [Ò] => Ò [Ó] => Ó
[Ô] => Ô [Õ] => Õ [Ö] => Ö [×] => ×
[Ø] => Ø [Ù] => Ù [Ú] => Ú [Û] => Û
[Ü] => Ü [Ý] => Ý [Þ] => Þ [ß] => ß
[à] => à [á] => á [â] => â [ã] => ã
[ä] => ä [å] => å [æ] => æ [ç] => ç
[è] => è [é] => é [ê] => ê [ë] => ë
[ì] => ì [í] => í [î] => î [ï] => ï
[ð] => ð [ñ] => ñ [ò] => ò [ó] => ó
[ô] => ô [õ] => õ [ö] => ö [÷] => ÷
[ø] => ø [ù] => ù [ú] => ú [û] => û
[ü] => ü [ý] => ý [þ] => þ [ÿ] => ÿ
["] => " [<] => < [>] => > [&] => &
)