English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP get_html_translation_table() function usage and example

   PHP String Function Manual

    The get_html_translation_table() function is used to return the conversion table after using htmlspecialchars() and htmlentities().

Syntax

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

Definition and usage

It returns the conversion table used by the htmlentities() and htmlspecialchars() functions.

Return value

It returns the conversion table as an array, with the original character as the key and the entity as the value.

Note: Special characters can be converted in multiple ways. For example: " can be converted to ", " or ". get_html_translation_table() returns the most commonly used one.

Parameter

Serial numberParameters and descriptions
1

table (required)

It contains information about which table HTML_ENTITIES or HTML_SPECIALCHARS should be returned

Possible values:

  • HTML_SPECIALCHARS - Default. Translate some characters that need to be URL-encoded so that they can be displayed correctly on the HTML page.

  • HTML_ENTITIES - Translate all characters that need to be URL-encoded so that they can be displayed correctly on the HTML page.

2

flags

Optional. Specifies which quotes the conversion table will include and which document type the conversion table is used for.

Available quote types:

  • ENT_COMPAT - Default. The conversion table includes double quote entities but not single quote entities.

  • ENT_QUOTES - The conversion table includes double quote entities and single quote entities.

  • ENT_NOQUOTES - The conversion table does not include double quote entities and single quote entities.

Additional flags specifying the document type for which the conversion table is applicable:

  • ENT_HTML401 - Default. HTML 4.01 Conversion table.

  • ENT_HTML5 - HTML 5 Conversion table.

  • ENT_XML1 - XML 1 Conversion table.

  • ENT_XHTML - Conversion table for XHTML.

3

encoding

Optional. A string that specifies the character set to be used.

Allowed values:

  • UTF-8 - Default. ASCII compatible multi-byte 8 bit Unicode

  • ISO-8859-1 - Western European

  • ISO-8859-15 - Western European (including the euro symbol) + ISO-8859-1 (including missing French and Finnish letters in the Cyrillic script)

  • cp866 - Cyrillic character set used in DOS

  • cp1251 - DOS-specific Cyrillic character set

  • cp1252 - Windows-specific Western European character set

  • KOI8-R - Russian

  • BIG5 - Traditional Chinese, mainly used in Taiwan

  • GB2312 - Simplified Chinese, national standard character set

  • BIG5-HKSCS - Big5 with Hong Kong extension5

  • Shift_JIS - Japanese

  • EUC-JP - Japanese

  • MacRoman - Character set used by the Mac operating system

Note:In PHP 5.4 earlier versions, unrecognized character sets will be ignored and replaced by ISO-8859-1 Instead, since PHP 5.4 Starting from PHP-8 instead.

Online Example

Try the following example, using the conversion table of HTML_SPECIALCHARS:

<?php
   //Use the conversion table of HTML_SPECIALCHARS
   print_r(get_html_translation_table(HTML_SPECIALCHARS));
?>
Test and see‹/›

Output Result

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

PHP String Function Manual