SPECIALCHARS: 5
ENTITIES: 1510
Has é? é
(exact counts vary by PHP version / flags)
How It Works
Build both tables. Same flags, different $table constant.
Count the keys. Specialchars stays tiny; entities is huge.
Check an accented letter. Often present only in the entities map.
Pick by need. XSS basics → specialchars; rich entity set → entities.
Frequently Asked Questions
It returns the character-to-entity mapping array used by htmlspecialchars() and htmlentities(). Keys are special characters; values are their HTML entity strings (for example '<' => '<').
array get_html_translation_table(int $table = HTML_SPECIALCHARS, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, string $encoding = 'UTF-8'). Use HTML_SPECIALCHARS or HTML_ENTITIES for $table.
HTML_SPECIALCHARS is a small map for &, <, >, and quotes. HTML_ENTITIES is a large map covering many symbols and accented letters—what htmlentities() can encode.
Pass it to strtr(): strtr($string, get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)). With matching flags this matches htmlspecialchars().
No. Build the table once before the loop and reuse the array. Rebuilding it every iteration wastes work.