PHP htmlentities() Function


The htmlentities() function converts characters to HTML entities. To convert HTML entities to characters, use the html_entity_decode() function. Use the get_html_translation_table() function to return the translation table used by htmlentities().

Syntax
htmlentities(string,flags,character-set,double_encode)
Parameters
Parameter Description
string (Required) Specify the string to convert.
flags (Optional) Specify how to handle quotation marks, invalid encoding, and the document type used.
  • ENT_COMPAT - Default. Encodes double quotes only.
  • ENT_QUOTES - Encodes double and single quotes .
  • ENT_NOQUOTES - Do not encode quotes.
  • ENT_IGNORE - The function ignores invalid encodings instead of returning an empty string. Avoid as it may affect security.
  • ENT_SUBSTITUTE - Replaces invalid encodings in the specified character set with the Unicode replacement character U+FFFD (UTF-8) or &#FFFD; instead of returning an empty string.
  • ENT_DISALLOWED - Replaces code points that are invalid in the specified document type with the Unicode replacement character U+FFFD (UTF-8) or &#FFFD;
character-set (Optional) A string indicating which character set to use.
  • UTF-8 - Default. ASCII compatible multi-byte 8-bit Unicode
  • ISO-8859-1 - Western Europe
  • ISO-8859-15 - Western European (adds euro symbol + French and Finnish characters not 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, primarily 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
double_encode (Optional) A Boolean value that indicates whether to encode existing HTML entities.
  • TRUE - Default. ASCII compatible multi-byte 8-bit Unicode
  • FALSE - Existing HTML entities will not be encoded
Example
<?php
$txt = '<a href="https://www.vrsofttech.com/">VR SOFT TECH</a>';
echo htmlentities($txt);
?>

Output

<a href="https://www.vrsofttech.com/">VR SOFT TECH</a>

Prev Next