YouTip LogoYouTip

Func String Get Html Translation Table

PHP get_html_translation_table() Function | Rookie Tutorial

PHP String Reference Manual PHP String Reference Manual

Example

Output the translation table used by the htmlspecialchars function:


Run Example ยป


Definition and Usage

The get_html_translation_table() function returns the translation table used by htmlentities() and htmlspecialchars().

Tip: Some characters can be encoded in several ways. The get_html_translation_table() function returns the most common encoding.


Syntax

get_html_translation_table(function,flags,character-set)
Parameters
Parameter Description
function Optional. Specifies which translation table to return. Possible values:
  • HTML_SPECIALCHARS - Default. Translates certain characters that need URL encoding to be displayed correctly in HTML pages.
  • HTML_ENTITIES - Translates all characters that need URL encoding to be displayed correctly in HTML pages.
flags Optional. Specifies which quotes the translation table will contain and which document type the translation table is for. Available quote types:
  • ENT_COMPAT - Default. Translation table contains double-quote entities, but not single-quote entities.
  • ENT_QUOTES - Translation table contains both double-quote and single-quote entities.
  • ENT_NOQUOTES - Translation table contains neither double-quote nor single-quote entities.
Additional flags to specify the document type for which the translation table is applicable:
  • ENT_HTML401 - Default. HTML 4.01 translation table.
  • ENT_HTML5 - HTML 5 translation table.
  • ENT_XML1 - XML 1 translation table.
  • ENT_XHTML - XHTML translation table.
character-set Optional. A string specifying the character set to use. Allowed values:
  • UTF-8 - Default. ASCII compatible multi-byte 8-bit Unicode
  • ISO-8859-1 - Western European
  • ISO-8859-15 - Western European (adds the Euro sign + French and Finnish letters missing in ISO-8859-1)
  • cp866 - DOS-specific Cyrillic character set
  • cp1251 - Windows-specific Cyrillic character set
  • cp1252 - Windows-specific Western European character set
  • KOI8-R - Russian
  • BIG5 - Traditional Chinese, mainly used in Taiwan
  • GB2312 - Simplified Chinese, national standard character set
  • BIG5-HKSCS - Big5 with Hong Kong extensions
  • Shift_JIS - Japanese
  • EUC-JP - Japanese
  • MacRoman - Character set used by Mac OS
Note: In versions before PHP 5.4, unrecognized character sets were ignored and replaced by ISO-8859-1. Since PHP 5.4, unrecognized character sets are ignored and replaced by UTF-8.

Technical Details

Return Value: Returns the translation table as an array, with the original characters as keys and the entities as values.
PHP Version: 4+
Changelog: In PHP 5, the default value for the character-set parameter changed to UTF-8.
In PHP 5.4, additional flags were added to specify the document type for which the translation table is applicable: ENT_HTML401, ENT_HTML5, ENT_XML1 and ENT_XHTML.
In PHP 5.3.4, the character-set parameter was added.

More Examples

Example 1

Translation table for HTML_SPECIALCHARS:


Displaying character and entity name:

Array
(
  =>"
 [&] =>&
 [<] =>&lt;
 [>] =>&gt;
 )

Example 2

Translation table for HTML_ENTITIES:


Displaying characters and their corresponding entity names:

Array
(
  =>&quot;
 [&] =>&amp;
 [&lt;
 [>] =>&gt;
  =>&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;
  =>&OElig;
  =>&oelig;
  =>&Scaron;
  =>&scaron;
  =>&Yuml;
  =>&fnof;
  =>&circ;
 [หœ] =>&tilde;
  =>&Alpha;
  =>&Beta;
  =>&Gamma;
  =>&Delta;
  =>&Epsilon;
  =>&Zeta;
  =>&Eta;
  =>&Theta;
  =>&Iota;
  =>&Kappa;
  =>&Lambda;
  =>&Mu;
  =>&Nu;
  =>&Xi;
  =>&Omicron;
  =>&Pi;
  =>&Rho;
  =>&Sigma;
  =>&Tau;
  =>&Upsilon;
  =>&Phi;
  =>&Chi;
  =>&Psi;
  =>&Omega;
  =>&alpha;
  =>&beta;
  =>&gamma;
  =>&delta;
  =>&epsilon;
  =>&zeta;
  =>&eta;
  =>&theta;
  =>&iota;
  =>&kappa;
  =>&lambda;
  =>&mu;
  =>&nu;
  =>&xi;
  =>&omicron;
  =>&pi;
  =>&rho;
  =>&sigmaf;
  =>&sigma;
  =>&tau;
  =>&upsilon;
  =>&phi;
  =>&chi;
  =>&psi;
  =>&omega;
  =>&thetasym;
  =>&upsih;
  =>&piv;
  =>&ensp;
  =>&emsp;
  =>&thinsp;
 [โ€Œ] =>&zwnj;
 [โ€] =>&zwj;
 [โ€Ž] =>&lrm;
 [โ€] =>&rlm;
 [โ€“] =>&ndash;
 [โ€”] =>&mdash;
 ['] =>&lsquo;
 ['] =>&rsquo;
 [โ€š] =>&sbquo;
  =>&ldquo;
  =>&rdquo;
 [โ€ž] =>&bdquo;
 [โ€ ] =>&dagger;
 [โ€ก] =>&Dagger;
 [โ€ข] =>&bull;
 [โ€ฆ] =>&hellip;
 [โ€ฐ] =>&permil;
 [โ€ฒ] =>&prime;
 [โ€ณ] =>&Prime;
 [โ€น] =>&lsaquo;
 [โ€บ] =>&rsaquo;
 [โ€พ] =>&oline;
 [โ„] =>&frasl;
 [โ‚ฌ] =>&euro;
  =>&image;
 [โ„˜] =>&weierp;
  =>&real;
 [โ„ข] =>&trade;
  =>&alefsym;
 [โ†] =>&larr;
 [โ†‘] =>&uarr;
 [โ†’] =>&rarr;
 [โ†“] =>&darr;
 [โ†”] =>&harr;
 [โ†ต] =>&crarr;
 [โ‡] =>&lArr;
 [โ‡‘] =>&uArr;
 [โ‡’] =>&rArr;
 [โ‡“] =>&dArr;
 [โ‡”] =>&hArr;
 [โˆ€] =>&forall;
 [โˆ‚] =>&part;
 [โˆƒ] =>&exist;
 [โˆ…] =>&empty;
 [โˆ‡] =>&nabla;
 [โˆˆ] =>&isin;
 [โˆ‰] =>&notin;
 [โˆ‹] =>&ni;
 [โˆ] =>&prod;
 [โˆ‘] =>&sum;
 [โˆ’] =>&minus;
 [โˆ—] =>&lowast;
 [โˆš] =>&radic;
 [โˆ] =>&prop;
 [โˆž] =>&infin;
 [โˆ ] =>&ang;
 [โˆง] =>&and;
 [โˆจ] =>&or;
 [โˆฉ] =>&cap;
 [โˆช] =>&cup;
 [โˆซ] =>&int;
 [โˆด] =>&there4;
 [โˆผ] =>&sim;
 [โ‰…] =>&cong;
 [โ‰ˆ] =>&asymp;
)
โ† Func String HebrevFunc String Fprintf โ†’