Easy Tutorial
❮ Php Syntax Func Filesystem Is Link ❯

PHP get_html_translation_table() Function

PHP String Reference Manual

Example

Output the translation table used by the htmlspecialchars function:


Definition and Usage

The get_html_translation_table() function returns the translation tables used by the htmlentities() and htmlspecialchars() functions.

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


Syntax

Parameter Description
function Optional. Specifies which translation table to return. Possible values: HTML_SPECIALCHARS - Default. Translates certain characters that need URL encoding to be displayed correctly in HTML pages. <br> HTML_ENTITIES - Translates all characters that need URL encoding to be displayed correctly in HTML pages.
flags Optional. Specifies which quotes the translation table will contain and for which document type the translation table is used. Available quote types: ENT_COMPAT - Default. The translation table includes double-quote entities but not single-quote entities. <br> ENT_QUOTES - The translation table includes both double-quote and single-quote entities. <br> ENT_NOQUOTES - The translation table does not include double-quote or single-quote entities. Additional flags for specifying the document type the translation table applies to: ENT_HTML401 - Default. Translation table for HTML 4.01. <br> ENT_HTML5 - Translation table for HTML 5. <br> ENT_XML1 - Translation table for XML 1. <br> ENT_XHTML - Translation table for XHTML.
character-set Optional. A string that specifies the character set to be used. Allowed values: UTF-8 - Default. ASCII-compatible multi-byte 8-bit Unicode. <br> ISO-8859-1 - Western European. <br> ISO-8859-15 - Western European (with euro sign + French and Finnish letters missing from ISO-8859-1). <br> cp866 - DOS-specific Cyrillic charset. <br> cp1251 - Windows-specific Cyrillic charset. <br> cp1252 - Windows-specific Western European charset. <br> KOI8-R - Russian. <br> BIG5 - Traditional Chinese, mainly used in Taiwan. <br> GB2312 - Simplified Chinese, national standard character set. <br> BIG5-HKSCS - Big5 with Hong Kong extensions. <br> Shift_JIS - Japanese. <br> EUC-JP - Japanese. <br> MacRoman - Character set used by Mac operating systems. Note: In versions of PHP prior to 5.4, unrecognized character sets were ignored and replaced by ISO-8859-1. Since PHP 5.4, unrecognized character sets are ignored and replaced by UTF-8.

Technical Details

Return Value: Returns the translation table as an array, with the original characters as keys and entities as values.
PHP Version: 4+
--- ---
Changelog: In PHP 5, the default value for the character-set parameter was changed to UTF-8. <br> <br> In PHP 5.4, additional flags for specifying the document type the translation table applies to were added: ENT_HTML401, ENT_HTML5, ENT_XML1, and ENT_XHTML. <br> <br> In PHP 5.3.4, the character-set parameter was added.
--- ---

More Examples

Example

Translation table for HTML_SPECIALCHARS:

Displaying character and entity name:


Example 2

Translation table for HTML_ENTITIES:

Displaying character and corresponding entity name:


❮ Php Syntax Func Filesystem Is Link ❯