PHP 8.5 get_html_translation_table() Function Use With Example

The get_html_translation_table() function returns the internal translation table used by htmlspecialchars() and htmlentities(). It is fully supported in PHP 8.5 with no breaking changes to its core behaviour.

Example

<?php
// Get the full HTML5 entity table
$table = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES | ENT_HTML5);

// Use it to manually encode a string
$string = "Hello & <World>";
$encoded = strtr($string, $table);

echo $encoded; 
// Output: Hello &amp; &lt;World&gt;
?>

Summary

Use get_html_translation_table() when you need the raw mapping array for custom encoding logic. For direct encoding, simply use htmlspecialchars() or htmlentities().

 

4 Views