htmlentities
Convert all applicable characters to HTML entities
&reftitle.description;
stringhtmlentities
stringstring
intflagsENT_COMPAT
stringcharset
booldouble_encodetrue
This function is identical to htmlspecialchars in all
ways, except with htmlentities, all characters which
have HTML character entity equivalents are translated into these entities.
If you're wanting to decode instead (the reverse) you can use
html_entity_decode.
&reftitle.parameters;
string
The input string.
flags
Like htmlspecialchars, the optional second
flags parameter lets you define what will
be done with 'single' and "double" quotes. It takes on one of three
constants with the default being ENT_COMPAT,
optionally combined with a fourth ENT_IGNORE (since
PHP 5.3.0):
Available flags constants
Constant Name
Description
ENT_COMPAT
Will convert double-quotes and leave single-quotes alone.
ENT_QUOTES
Will convert both double and single quotes.
ENT_NOQUOTES
Will leave both double and single quotes unconverted.
ENT_IGNORE
Silently discard invalid code unit sequences instead of returning
an empty string. Added in PHP 5.3.0. This is provided for backwards
compatibility; avoid using it as it may have security implications.
charset
Like htmlspecialchars, it takes an optional
third argument charset which defines character
set used in conversion.
Presently, the ISO-8859-1 character set is used as the default.
However, this default is very likely to change in future versions of
PHP; the programmer is highly encouraged to specify a value.
&reference.strings.charsets;
double_encode
When double_encode is turned off PHP will not
encode existing html entities. The default is to convert everything.
&reftitle.returnvalues;
Returns the encoded string.
&reftitle.changelog;
&Version;
&Description;
5.3.0
The constant ENT_IGNORE was added.
5.2.3
The double_encode parameter was added.
4.1.0
The charset parameter was added.
4.0.3
The flags parameter was added.
&reftitle.examples;
A htmlentities example
bold";
// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str);
// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str, ENT_QUOTES);
?>
]]>
Usage of ENT_IGNORE
]]>
&reftitle.seealso;
html_entity_decode
get_html_translation_table
htmlspecialchars
nl2br
urlencode