Categories: PHP

get_html_translation_table – PHP String Functions

Syntax :

get_html_translation_table ( strings, flags, encoding/character-set );

Description :

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

Note : htmlentities() function is reverse of it.

Parameter :

  • strings – This is Required parameter. String which needs to be converted.
  • flags – This is an Optional parameter. The default value for flags is ENT_COMPAT | ENT_HTML401. It elaborates how to handle quotes, invalid encoding and the used document type.

[table caption=”List of available flags constants are” max-width=”100%” colwidth=”25%|75%” colalign=”left|left”]

Constant Name, Description
ENT_COMPAT, It will decodes double-quotes only.
ENT_QUOTES, It will decodes both double and single quotes.
ENT_NOQUOTES, It will not decodes both double and single quotes.
ENT_HTML401, Handle code as HTML 4.01.
ENT_XML1, Handle code as XML 1.
ENT_XHTML, Handle code as XHTML.
ENT_HTML5, Handle code as HTML 5.
[/table]

  • encoding/character-set – This is an Optional parameter. A string that specifies which character-set to use.
    • If omitted, the default value of the encoding varies depending on the PHP version in use. In PHP 5.6 and later, the default_charset configuration option is used as the default value. PHP 5.4 and 5.5 will use UTF-8 as the default. Earlier versions of PHP use ISO-8859-1.Although this argument is technically optional, you are highly encouraged to specify the correct value for your code if you are using PHP 5.5 or earlier, or if your default_charset configuration option may be set incorrectly for the given input.The following character sets are supported:
    • Supported charsets are :
      [table caption=”List of Supported charsets are” max-width=”100%” colwidth=”25%|75%” colalign=”left|left”]
      Charset Aliases, Description
      ISO-8859-1,Western European Latin-1.
      ISO-8859-5 , Little used cyrillic charset (Latin/Cyrillic).
      ISO-8859-15 , Western European,
      UTF-8, ASCII compatible multi-byte 8-bit Unicode.
      cp866 ibm866, DOS-specific Cyrillic charset.
      cp1251 , Windows-specific Cyrillic charset.
      cp1252 , Windows specific charset for Western European.
      KOI8-R,  Russian.
      BIG5 950, Traditional Chinese. mainly used in Taiwan.
      GB2312 936, Simplified Chinese. national standard character set.
      BIG5-HKSCS , with Hong Kong extensions. Traditional Chinese.
      Shift_JIS , Japanese
      EUC-JP , Japanese
      MacRoman Charset, that was used by Mac OS.
      Empty string or ”, An empty string activates detection from script encoding (Zend multibyte) or default_charset and current locale (see nl_langinfo() and setlocale()) so in this order. Not recommended.
      [/table]

Note : Any other character sets are not recognized. The default encoding will be used instead and a warning will be emitted.


Output :

This will return a decoded string.


ChangeLog :

[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, Description
PHP 5.4.0 , The default value for the encoding parameter was changed to UTF-8.
PHP 5.4.0 ,The constants ENT_HTML401 / ENT_XML1 / ENT_XHTML / ENT_HTML5 were introduced.
PHP 5.3.4 , The encoding parameter was added.
[/table]


Related articles : htmlentities(), htmlspecialchars(), html_entity_decode().


get_html_translation_table() – PHP Functions Example 1 : Listing table for HTML_SPECIALCHARS:
<?php
print_r (get_html_translation_table()); // HTML_SPECIALCHARS is default.
?>

See below is the output of above code in web browser.

Array
(
[“] => &quot;
[&] => &amp;
[<] => &lt;
[>] => &gt;
)


get_html_translation_table() – PHP Functions Example 2 :
<?php
print_r (get_html_translation_table(HTML_ENTITIES));
?>

See below is the output of above code in Web browser.

Array
(
[“] => &quot;
[&] => &amp;
[<] => &lt;
[>] => &gt;
[Â ] => &nbsp;
[¡] => &iexcl;
[¢] => &cent;
..]

jyoti rani

Recent Posts

Modern Toys, Magical Moments: Why the Best Toy Shop in Noida Is More Than Just a Store

When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…

6 months ago

Rediscovering Joy: A New Era of Creativity & Comfort in Toy Stores

In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…

6 months ago

Unboxing Imagination: Discovering the Joy of Play at a Toy Store in Noida

In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…

6 months ago

Imagination Unboxed: Discover Joy at the Toy Shop in Delhi

In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…

6 months ago

Play with Purpose: Discovering the Ultimate Toy Store in Noida

When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…

6 months ago

From Tears to Toys: Exploring Modern Childhood through Delhi’s Favorite Toy Shop

In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…

6 months ago