get_html_translation_table
(PHP 4, PHP 5, PHP 7, PHP 8)
Returns the translation table used by htmlspecialchars and htmlentities
Description
get_html_translation_table() will return the translation table that is used internally for htmlspecialchars() and htmlentities().
Special characters can be encoded in several ways. E.g. " can be encoded as ", " or ". get_html_translation_table() returns only the form used by htmlspecialchars() and htmlentities().
Parameters
tableWhich table to return. Either
HTML_ENTITIESorHTML_SPECIALCHARS.flagsA 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.Constant Name Description ENT_COMPATTable will contain entities for double-quotes, but not for single-quotes. ENT_QUOTESTable will contain entities for both double and single quotes. ENT_NOQUOTESTable will neither contain entities for single quotes nor for double quotes. ENT_SUBSTITUTEReplace invalid code unit sequences with a Unicode Replacement Character U+FFFD (UTF-8) or � (otherwise) instead of returning an empty string. ENT_HTML401Table for HTML 4.01. ENT_XML1Table for XML 1. ENT_XHTMLTable for XHTML. ENT_HTML5Table for HTML 5. encodingEncoding to use. If omitted, the default value for this argument is UTF-8.
Charsets
Return Values
Returns the translation table as an array, with the original characters as keys and entities as values.
Changelog
| Version | Description |
|---|---|
| 8.1.0 | flags changed from ENT_COMPAT to ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401. |
Examples
Translation Table Example
<?php
var_dump(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES | ENT_HTML5));
?>The above example will output something similar to:
array(1510) {
["
"]=>
string(9) "
"
["!"]=>
string(6) "!"
["""]=>
string(6) """
["#"]=>
string(5) "#"
["$"]=>
string(8) "$"
["%"]=>
string(8) "%"
["&"]=>
string(5) "&"
["'"]=>
string(6) "'"
// ...
}