get_html_translation_table()
get_html_translation_table() — Returns the translation table used by htmlspecialchars() and htmlentities().
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
get_html_translation_table() will return the translation table that is used internally for htmlspecialchars() and htmlentities().
Signature
get_html_translation_table(int $table = HTML_SPECIALCHARS, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, string $encoding = "UTF-8"): array
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $table | int | Which table to return. Either HTML_ENTITIES or HTML_SPECIALCHARS. |
| $flags | int | A bitmask of one or more of the following flags, which specify which quotes the table will contain as well as which document type the table is for. The default is ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401. Available flags constants Constant Name Description ENT_COMPAT Table will contain entities for double-quotes, but not for single-quotes. ENT_QUOTES Table will contain entities for both double and single quotes. ... |
| $encoding | string | Encoding to use. If omitted, the default value for this argument is UTF-8. |
Return value
Returns the translation table as an array, with the original characters as keys and entities as values.
Example
A runnable snippet:
var_dump(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES | ENT_HTML5));
Output:
array(1510) { [" "]=> string(9) "
" ["!"]=> string(6) "!" ["""]=> string(6) """ ["#"]=> string(5) "#" ["$"]=> string(8) "$" ["%"]=> string(8) "%" ["&"]=> string(5) "&" ["'"]=> string(6) "'" // ... }
Changelog
| Version | Change |
|---|---|
| 8.1.0 | flags changed from ENT_COMPAT to ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401. |
See also
htmlspecialchars(), htmlentities(), html_entity_decode()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page get_html_translation_table() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.