PHP String get_html_translation_table() Function

The get_html_translation_table() function in PHP is used to return the translation table used by the htmlentities() and htmlspecialchars() functions.

Syntax

get_html_translation_table ([ int $table = HTML_SPECIALCHARS [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = "UTF-8" ]]] )

Parameter

table (optional)- This parameter specifies which translation table to return. It either returns HTML_ENTITIES or HTML_SPECIALCHARS.

flags (optional)- This parameter specifies which quotes the table will contain and which document type the table is for. The available flag constants are as follows:

  • ENT_COMPAT- Table contains entities only for double-quotes
  • ENT_QUOTES- The Table contains entities for both double and single quotes
  • ENT_NOQUOTES- Table contains entities neither for single quotes nor for double quotes.
  • ENT_HTML401- Table specifically for HTML 4.01.
  • ENT_XML1- Table for XML 1.
  • ENT_XHTML- Table for XHTML.
  • ENT_HTML5- Table for HTML 5.

Character-set (optional)- It represents a string that specifies which character-set to use. The following character set are supported:

  • 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 charset
  • cp1251 - Windows-specific Cyrillic charset
  • cp1252 - Windows specific charset for Western European
  • 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 that was used by Mac OS

Return

This function returns the translation table as an array, with the original characters as keys and entities as values.

Example 1

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

Output

Array
 (
     ["] => "
     [&] => & 
     [<] => <
     [>] => >
     [ ] =>  
     [¡] => ¡ 
     [¢] => ¢
     [£] => £
     [¤] => ¤
     [¥] => ¥ 
     [¦] => ¦
     [§] => §
     [¨] => ¨
     [©] => © 
     [ª] => ª
     [«] => «
     [¬] => ¬
     [­] => ­
     [®] => ®
     [¯] => ¯
     [°] => ° 
     [±] => ±
     [²] => ²
     [³] => ³
     [´] => ´
     [µ] => µ 
     [¶] => ¶
     [·] => ·
     [¸] => ¸
     [¹] => ¹
     [º] => º 
     [»] => »
     [¼] => ¼
     [½] => ½
     [¾] => ¾
     [¿] => ¿ 
     [À] => À
     [Á] => Á
     [Â] => Â
     [Ã] => Ã
     [Ä] => Ä
     [Å] => Å
     [Æ] => Æ 
     [Ç] => Ç
     [È] => È
     [É] => É
     [Ê] => Ê
     [Ë] => Ë
     [Ì] => Ì 
     [Í] => Í
     [Î] => Î
     [Ï] => Ï
     [Ð] => Ð
     [Ñ] => Ñ
     [Ò] => Ò
     [Ó] => Ó 
     [Ô] => Ô
     [Õ] => Õ
     [Ö] => Ö
     [×] => ×
     [Ø] => Ø
     [Ù] => Ù
     [Ú] => Ú
     [Û] => Û 
     [Ü] => Ü
     [Ý] => Ý
     [Þ] => Þ
     [ß] => ß
     [à] => à
     [á] => á
     [â] => â 
     [ã] => ã
     [ä] => ä
     [å] => å
     [æ] => æ
     [ç] => ç
     [è] => è
     [é] => é
     [ê] => ê 
     [ë] => ë
     [ì] => ì
     [í] => í
     [î] => î
     [ï] => ï
     [ð] => ð
     [ñ] => ñ 
     [ò] => ò
     [ó] => ó
     [ô] => ô
     [õ] => õ
     [ö] => ö
     [÷] => ÷
     [ø] => ø
     [ù] => ù 
     [ú] => ú
     [û] => û
     [ü] => ü
     [ý] => ý
     [þ] => þ
     [ÿ] => ÿ
     [Œ] => Œ 
     [œ] => œ
     [Š] => Š
     [š] => š
     [Ÿ] => Ÿ
     [ƒ] => ƒ
     [ˆ] => ˆ
     [˜] => ˜
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [–] => –
     [—] => —
     [‘] => ‘ 
     [’] => ’
     [‚] => ‚
     [“] => “
     [”] => ”
     [„] => „
     [†] => †
     [‡] => ‡
     [•] => • 
     […] => …
     [‰] => ‰
     [?] => ?
     [?] => ?
     [‹] => ‹
     [›] => ›
     [?] => ?
     [?] => ?
     [€] => € 
     [?] => ?
     [?] => ?
     [?] => ?
     [™] => ™
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ?
     [?] => ? 
     [?] => √
     [?] => ∝
     [?] => ∞
     [?] => ∠
     [?] => ∧
     [?] => ∨
     [?] => ∩
     [?] => ∪
     [?] => ∫
     [?] => ∴
     [?] => ∼
     [?] => ≅
     [?] => ≈
     [?] => ≠
     [?] => ≡
     [?] => ≤
     [?] => ≥
     [?] => ⊂
     [?] => ⊃
     [?] => ⊄
     [?] => ⊆
     [?] => ⊇
     [?] => ⊕
     [?] => ⊗
     [?] => ⊥
     [?] => ⋅
     [?] => ⌈
     [?] => ⌉
     [?] => ⌊ 

Example 2

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

Output

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

Example 3

<?php
print_r (get_html_translation_table()); // The HTML_SPECIALCHARS is default.
?> 

Output

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

Related Topics

PHP htmlspecialchars_decode() Function

PHP htmlspecialchars_decode() Function The htmlspecialchars_decode() function in PHP convert some predefined HTML entities to characters. The some predefined HTML entities that will be decoded are as follows: &amp; OR & (ampersand)&quot; OR " (double quote)&#039;...

2 minutes read.

PHP foreach Loop

PHP foreach Loop with Example PHP foreach loop is used to loop through the associative arrays. Syntax: foreach($array as $key => $value) { //Statement } $array = associative array. $key = array key. &value =...

2 minutes read.

PHP chop() Function

PHP chop() Function The chop() function in PHP removes whitespaces or other predefined characters from the right end of the specified string. Syntax chop(str,charlist) Parameter str(required)- This parameter specifies the string to check. charlist(optional)- This parameter...

1 minute read.

PHP array_uintersect() Function

PHP array_uintersect() Function The array_uintersect() function in PHP calculates the intersection of arrays by comparing the data by a callback function. It returns an array containing all the values of the first input array that are...

2 minutes read.

PHP array_udiff_assoc() Function

PHP array_udiff_assoc() Function The array_udiff_assoc () function in PHP computes the difference between the specified arrays with additional index check and compares the data by a callback function. It returns all the values from array1 that are not...

1 minute read.

PHP unserialize() Function

PHP unserialize() Function The unserialize() function in PHP takes a single serialized variable and converts it back into a PHP value. Syntax unserialize ( string $str [, array $options ] ) Parameter value(required)- This parameter represents the serialized string. options(optional)- This parameter signifies any options to be...

1 minute read.

PHP nl2br() Function

PHP nl2br() Function The nl2br() function in PHP inserts HTML line breaks before all newlines in a string. Syntax nl2br ( string $string [, bool $is_xhtml] ) Parameter sting(required)- This parameter specifies the input string. is_xhtml(optional)- This parameter states whether to use XHTML compatible line breaks...

1 minute read.

PHP join() Function

PHP join() Function The join() function of PHP returns a string from the elements of an array. This function is an alias of the implode() function. Syntax join(separator,array) Parameter separator(Optional)- Specifies what to put between the array elements. The default...

1 minute read.

PHP serialize() Function

PHP serialize() Function The serialize() function in PHP is used to convert a storable representation of a value. Syntax serialize ( mixed $value ) Parameter value(required)- This parameter represents the value to be serialized. Return This function returns a string containing a byte-stream representation...

1 minute read.

PHP quotemeta() Function

PHP quotemeta() Function The quotemeta() function in PHP quotes the meta characters and returns a string with a backslash character (\) before some predefine characters. The predefined characters are as follows: period ...

1 minute read.

PHP array_walk_recursive() Function

PHP array_walk_recursive() Function The array_walk_recursive () function in PHP is used to apply a user-defined callback function recursively to each element of the array. This function returns a Boolean TRUE on success or FALSE on failure. Syntax array_walk_recursive ( array &$array , callable $callback [, mixed $userdata = NULL ] ) Parameter array(required)- This array represents the...

1 minute read.

PHP strcmp() Function

PHP strcmp() Function The strcmp() function in PHP compares two strings. It is a binary-safe case-sensitive string function. This function is similar to the strncmp() function, with the difference that you can specify the number of characters from each...

1 minute read.

PHP metaphone() Function

PHP metaphone() Function The metaphone() function in PHP calculates the metaphone key (representing how a string sounds or pronounced) of a string. This function is used to text search and text matching or spelling...

1 minute read.

PHP Comment

PHP commentis a line of code that is not executed. It is often used by developer to understand the code. PHP support single and multiple comments. In other language like C,...

1 minute read.

PHP strspn() Function

PHP strspn() Function The strspn() function of PHP finds the length of the initial segment of string that contains only characters from the mask parameter. Syntax strspn(string$subject,string$mask[,int$start[,int$length]] ) Parameter subject(required)- This parameter represents the input string. mask(required)- This parameter specifies the characters to find. start (optional)- It signifies the position in the string to start...

1 minute read.

PHP key() Function

PHP key() Function The key() function in PHP fetches a key from an array and returns the index element of the current array position. Syntax key ( array $array ) Parameter array(required)- This parameter represents the input array. Return This function returns the key of the...

1 minute read.

PHP Functions

PHP functions are used to reuse piece of code many times.  There are various built-in functions in PHP. A function will be executed by a call to the function. Following are...

3 minutes read.

PHP array_combine() Function

PHP array_combine() Function The array_combine() function in PHP is used to create an array by combining two arrays i.e., one array for keys and another array for its values. Syntax array_combine ( array $keys , array $values ) Parameter keys(required)- This parameter represents an array which acts...

1 minute read.

PHP next() Function

PHP next() Function The next() function in PHP advances or moves the internal array pointer one place forward and returns the next array value. Syntax next ( array &$array ) Parameter array(required)- This parameter represents the input array. Return This parameter returns the next array value...

1 minute read.

PHP sprintf() Function

PHP sprintf() Function The sprintf() function in PHP is used to write a formatted string to a variable and returns a formatted string. PHP 4 and above versions support the sprintf() function. The related functions are...

8 minutes read.