htmlentitiesConvert all applicable characters to HTML entities
&reftitle.description;
stringhtmlentitiesstringstringintflagsENT_COMPAT | ENT_HTML401stringencoding'UTF-8'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 want to decode instead (the reverse) you can use
html_entity_decode.
&reftitle.parameters;
string
The input string.
flags
A bitmask of one or more of the following flags, which specify how to handle quotes,
invalid code unit sequences and the used document type. The default is
ENT_COMPAT | ENT_HTML401.
Available flags constantsConstant NameDescriptionENT_COMPATWill convert double-quotes and leave single-quotes alone.ENT_QUOTESWill convert both double and single quotes.ENT_NOQUOTESWill leave both double and single quotes unconverted.ENT_IGNORE
Silently discard invalid code unit sequences instead of returning
an empty string. Using this flag is discouraged as it
may have security implications.
ENT_SUBSTITUTE
Replace invalid code unit sequences with a Unicode Replacement Character
U+FFFD (UTF-8) or &#FFFD; (otherwise) instead of returning an empty string.
ENT_DISALLOWED
Replace invalid code points for the given document type with a
Unicode Replacement Character U+FFFD (UTF-8) or &#FFFD;
(otherwise) instead of leaving them as is. This may be useful, for
instance, to ensure the well-formedness of XML documents with
embedded external content.
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.
encoding
Like htmlspecialchars,
htmlentities takes an optional third argument
encoding which defines encoding used in
conversion.
If omitted, the default value for this argument is ISO-8859-1 in
versions of PHP prior to 5.4.0, and UTF-8 from PHP 5.4.0 onwards.
Although this argument is technically optional, you are highly
encouraged to specify the correct value for your code.
&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.
If the input string contains an invalid code unit
sequence within the given encoding an empty string
will be returned, unless either the ENT_IGNORE or
ENT_SUBSTITUTE flags are set.
&reftitle.changelog;
&Version;&Description;5.4.0
The default value for the encoding parameter was
changed to UTF-8.
5.4.0
The constants ENT_SUBSTITUTE, ENT_DISALLOWED,
ENT_HTML401, ENT_XML1,
ENT_XHTML and ENT_HTML5 were added.
5.3.0
The constant ENT_IGNORE was added.
5.2.3
The double_encode parameter was added.
4.1.0
The encoding 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_decodeget_html_translation_tablehtmlspecialcharsnl2brurlencode