Jump to: navigation, search

Php get html translation table

From w3cyberlearnings

Contents

PHP function get_html_translation_table

This function returns the translation table used by htmlspecialchars() and htmlentities()

Syntax get_html_translation_table

  • function: HTML_ENTITIES, HTML_SPECIALCHARS (Default)
  • quotestyle: ENT_COMPAT (Encodes double quotes), ENT_QUOTES (Double and Single Quotes), ENT_NOQUOTES (No Single and double encode)
get_html_translation_table(function,quotestyle)

Example 1

<?php
print_r(get_html_translation_table());
?>

Output

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

Example 2

<?php
print_r (get_html_translation_table(HTML_ENTITIES));
?>

Output

Array
(
    [ ] =>  
    [¡] => ¡
    [¢] => ¢
    [£] => £
    [¤] => ¤
    [¥] => ¥
    [¦] => ¦
    [§] => §
    [¨] => ¨
    [©] => ©
    [ª] => ª
    [«] => «
    [¬] => ¬
    [­] => ­
    [®] => ®
    [¯] => ¯
    [°] => °
    [±] => ±
    [²] => ²
    [³] => ³
    [´] => ´
    [µ] => µ
    [¶] => ¶
    [·] => ·
    [¸] => ¸
    [¹] => ¹
    [º] => º
    [»] => »
    [¼] => ¼
    [½] => ½
    [¾] => ¾
    [¿] => ¿
    [À] => À
    [Á] => Á
    [Â] => Â
    [Ã] => Ã
    [Ä] => Ä
    [Å] => Å
    [Æ] => Æ
    [Ç] => Ç
    [È] => È
    [É] => É
    [Ê] => Ê
    [Ë] => Ë
    [Ì] => Ì
    [Í] => Í
    [Î] => Î
    [Ï] => Ï
    [Ð] => Ð
    [Ñ] => Ñ
    [Ò] => Ò
    [Ó] => Ó
    [Ô] => Ô
    [Õ] => Õ
    [Ö] => Ö
    [×] => ×
    [Ø] => Ø
    [Ù] => Ù
    [Ú] => Ú
    [Û] => Û
    [Ü] => Ü
    [Ý] => Ý
    [Þ] => Þ
    [ß] => ß
    [à] => à
    [á] => á
    [â] => â
    [ã] => ã
    [ä] => ä
    [å] => å
    [æ] => æ
    [ç] => ç
    [è] => è
    [é] => é
    [ê] => ê
    [ë] => ë
    [ì] => ì
    [í] => í
    [î] => î
    [ï] => ï
    [ð] => ð
    [ñ] => ñ
    [ò] => ò
    [ó] => ó
    [ô] => ô
    [õ] => õ
    [ö] => ö
    [÷] => ÷
    [ø] => ø
    [ù] => ù
    [ú] => ú
    [û] => û
    [ü] => ü
    [ý] => ý
    [þ] => þ
    [ÿ] => ÿ
    [&] => &
    ["] => "
    [<] => <
    [>] => >
)

Example 3

<?php

$entities = get_html_translation_table(HTML_ENTITIES);

foreach ($entities as $entity) {
	$new_entities[$entity] = htmlspecialchars($entity);
}

print_r($new_entities);

?>

Output

Array
(
    [ ] => &nbsp;
    [¡] => &iexcl;
    [¢] => &cent;
    [£] => &pound;
    [¤] => &curren;
    [¥] => &yen;
    [¦] => &brvbar;
    [§] => &sect;
    [¨] => &uml;
    [©] => &copy;
    [ª] => &ordf;
    [«] => &laquo;
    [¬] => &not;
    [­] => &shy;
    [®] => &reg;
    [¯] => &macr;
    [°] => &deg;
    [±] => &plusmn;
    [²] => &sup2;
    [³] => &sup3;
    [´] => &acute;
    [µ] => &micro;
    [¶] => &para;
    [·] => &middot;
    [¸] => &cedil;
    [¹] => &sup1;
    [º] => &ordm;
    [»] => &raquo;
    [¼] => &frac14;
    [½] => &frac12;
    [¾] => &frac34;
    [¿] => &iquest;
    [À] => &Agrave;
    [Á] => &Aacute;
    [Â] => &Acirc;
    [Ã] => &Atilde;
    [Ä] => &Auml;
    [Å] => &Aring;
    [Æ] => &AElig;
    [Ç] => &Ccedil;
    [È] => &Egrave;
    [É] => &Eacute;
    [Ê] => &Ecirc;
    [Ë] => &Euml;
    [Ì] => &Igrave;
    [Í] => &Iacute;
    [Î] => &Icirc;
    [Ï] => &Iuml;
    [Ð] => &ETH;
    [Ñ] => &Ntilde;
    [Ò] => &Ograve;
    [Ó] => &Oacute;
    [Ô] => &Ocirc;
    [Õ] => &Otilde;
    [Ö] => &Ouml;
    [×] => &times;
    [Ø] => &Oslash;
    [Ù] => &Ugrave;
    [Ú] => &Uacute;
    [Û] => &Ucirc;
    [Ü] => &Uuml;
    [Ý] => &Yacute;
    [Þ] => &THORN;
    [ß] => &szlig;
    [à] => &agrave;
    [á] => &aacute;
    [â] => &acirc;
    [ã] => &atilde;
    [ä] => &auml;
    [å] => &aring;
    [æ] => &aelig;
    [ç] => &ccedil;
    [è] => &egrave;
    [é] => &eacute;
    [ê] => &ecirc;
    [ë] => &euml;
    [ì] => &igrave;
    [í] => &iacute;
    [î] => &icirc;
    [ï] => &iuml;
    [ð] => &eth;
    [ñ] => &ntilde;
    [ò] => &ograve;
    [ó] => &oacute;
    [ô] => &ocirc;
    [õ] => &otilde;
    [ö] => &ouml;
    [÷] => &divide;
    [ø] => &oslash;
    [ù] => &ugrave;
    [ú] => &uacute;
    [û] => &ucirc;
    [ü] => &uuml;
    [ý] => &yacute;
    [þ] => &thorn;
    [ÿ] => &yuml;
    [&] => &amp;
    ["] => &quot;
    [<] => &lt;
    [>] => &gt;
)

Example 4

  • HTML_SPECIALCHARS
  • Encode without single and double quotes.
<?php

print_r(get_html_translation_table(HTML_SPECIALCHARS, ENT_NOQUOTES));
?>

Output

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

Related Functions


Navigation
Web
SQL
MISC
References