String get_html_translation_table() Function

The get_html_translation_table() is the in-built function of PHP. This function returns the translation table which is used by htmlspecialchars() and htmlentities() functions. There are several ways to encode the special characters. E.g. ", ", or &#34.

Syntax

For example

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

Note: Special character can be encoded in multiple ways. E.g. ", ", or &#34. get_html_translation_table() function returns only the form used by htmlspecialchars() and htmlentities().

Parameters

  1. table
    It is an optional parameter, specifies that which table is to be returned, i.e., either HTML_ENTITIES or HTML_SPECIALCHARS.
  2. flags
    The flags parameter is also an optional parameter. A bitmask of one or more of the following flags specifies that which quotes the table will contain and which type of document the table is for. By default it is ENT_COMPAT | ENT_HTML 401.
    The available quote styles are given below:
    • ENT_COMPAT - Table contains entities for the double-quotes rather than single-quote.
    • ENT_QUOTES - Table contains entities for double-quote as well as single-quote.
    • ENT_NOQUOTES - Table does not contain entities for both double and single quotes.
    • ENT_HTML401 - Table for HTML 4.01.
    • ENT_XML1 - Table for XML 1.
    • ENT_XHTML - Table for XHTML.
    • ENT_HTML5 - Table for HTML5.
  3. encoding
    It is encoding which is used in this function. If omitted, before PHP 5.4.0 version the default value for this argument is ISO-8859, and UTF-8 from PHP 5.4.0 onwards.
    There are character sets given below which are supported.
CharsetAliasesDescription
ISO-8859-1ISO-8859-1Western European, Latin-1
ISO-8859-5ISO-8859-5Little used Cyrillic charset (Latin/Cyrillic)
ISO-8859-15ISO-8859-15Western European, Latin-9. It adds the Euro sign, French and Finnish letters missing in Latin-1 (ISO-8859-1)
UTF-8ASCII compatible multi-byte 8-bit Unicode.
cp866Ibm866, 866DOS-specific Cyrillic charset.
cp1251Windows-1251, win-1251, 1251Windows-specific Cyrillic charset.
cp1252Windows-1252, 1252Windows-specific charset for Western European.
KOI8-Rkoi8r, Koi8-ruRussian.
BIG5950Traditional Chinese that is mainly used in Taiwan.
GB2312936Simplified Chinese, national standard character set.
BIG5-HKSCSBig5 with Hong Kong Extension, traditional Chinese.
Shift_JIScp932, 932, SJJS, SJJS-winJapanese
EUC-JPEUCJP, eucJP-winJapanese
MacRomanCharset which was used by Mac OS.
"An empty string activates detection from default_charset, script encoding (Zend multibyte), and current locale in this order. Not recommended.

Note: No any other character sets are recognized. Instead of that, the default encoding will be used, and a warning will be emitted.

Technical details

Value return by get_html_translation_table()

This function returns the translation table as an array, with the original character as a key and entities as values.

Version:

PHP 4 and above version.

Changelog

VersionDescription
5.4.0By default the value for encoding parameter was changed to UTF-8.
5.4.0ENT_HTML401, ENT_XHTML, ENT_XML1, and ENT_HTML5 constant were added in PHP 5.4.
5.3.4The encoding parameter was added in PHP 5.3.4.

Example 1

Output:

PHP string str_getcsv Function

Note: By default parameter is HTML_SPECIALCHARS

Or

Output:

PHP string str_getcsv Function

Example 2

Output:

PHP string str_getcsv Function
Next TopicPHP String




Latest Courses