Javatpoint Logo
Javatpoint Logo

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.
Charset Aliases Description
ISO-8859-1 ISO-8859-1 Western European, Latin-1
ISO-8859-5 ISO-8859-5 Little used Cyrillic charset (Latin/Cyrillic)
ISO-8859-15 ISO-8859-15 Western European, Latin-9. It adds the Euro sign, French and Finnish letters missing in Latin-1 (ISO-8859-1)
UTF-8 ASCII compatible multi-byte 8-bit Unicode.
cp866 Ibm866, 866 DOS-specific Cyrillic charset.
cp1251 Windows-1251, win-1251, 1251 Windows-specific Cyrillic charset.
cp1252 Windows-1252, 1252 Windows-specific charset for Western European.
KOI8-R koi8r, Koi8-ru Russian.
BIG5 950 Traditional Chinese that is mainly used in Taiwan.
GB2312 936 Simplified Chinese, national standard character set.
BIG5-HKSCS Big5 with Hong Kong Extension, traditional Chinese.
Shift_JIS cp932, 932, SJJS, SJJS-win Japanese
EUC-JP EUCJP, eucJP-win Japanese
MacRoman Charset 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

Version Description
5.4.0 By default the value for encoding parameter was changed to UTF-8.
5.4.0 ENT_HTML401, ENT_XHTML, ENT_XML1, and ENT_HTML5 constant were added in PHP 5.4.
5.3.4 The 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




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA