2010-03-28 22:10:10 +00:00
<?xml version="1.0" encoding="utf-8"?>
2009-07-11 09:08:43 +00:00
<!-- $Revision$ -->
2020-12-05 14:30:42 +00:00
<refentry xml:id= "function.htmlentities" xmlns= "http://docbook.org/ns/docbook" xmlns:xlink= "http://www.w3.org/1999/xlink" >
2007-06-15 19:01:26 +00:00
<refnamediv >
<refname > htmlentities</refname>
<refpurpose > Convert all applicable characters to HTML entities</refpurpose>
</refnamediv>
2007-06-15 19:01:57 +00:00
<refsect1 role= "description" >
&reftitle.description;
2007-06-15 19:01:26 +00:00
<methodsynopsis >
<type > string</type> <methodname > htmlentities</methodname>
<methodparam > <type > string</type> <parameter > string</parameter> </methodparam>
2021-10-27 08:50:38 +00:00
<methodparam choice= "opt" > <type > int</type> <parameter > flags</parameter> <initializer > <constant > ENT_QUOTES</constant> | <constant > ENT_SUBSTITUTE</constant> | <constant > ENT_HTML401</constant> </initializer> </methodparam>
2020-12-05 14:30:42 +00:00
<methodparam choice= "opt" > <type class= "union" > <type > string</type> <type > null</type> </type> <parameter > encoding</parameter> <initializer > &null; </initializer> </methodparam>
2018-01-25 19:11:34 +00:00
<methodparam choice= "opt" > <type > bool</type> <parameter > double_encode</parameter> <initializer > &true; </initializer> </methodparam>
2007-06-15 19:01:26 +00:00
</methodsynopsis>
<para >
2007-06-15 19:01:57 +00:00
This function is identical to <function > htmlspecialchars</function> in all
ways, except with <function > htmlentities</function> , all characters which
have HTML character entity equivalents are translated into these entities.
2007-06-15 19:01:26 +00:00
</para>
<para >
2012-01-27 20:42:48 +00:00
If you want to decode instead (the reverse) you can use
2007-06-15 19:01:57 +00:00
<function > html_entity_decode</function> .
</para>
</refsect1>
<refsect1 role= "parameters" >
&reftitle.parameters;
<para >
<variablelist >
<varlistentry >
<term > <parameter > string</parameter> </term>
<listitem >
<para >
The input string.
</para>
</listitem>
</varlistentry>
<varlistentry >
2010-10-11 01:15:45 +00:00
<term > <parameter > flags</parameter> </term>
2007-06-15 19:01:57 +00:00
<listitem >
<para >
2011-09-17 11:32:28 +00:00
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
2021-09-23 13:00:33 +00:00
<literal > ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401</literal> .
2007-06-15 19:01:57 +00:00
<table >
2010-10-11 01:15:45 +00:00
<title > Available <parameter > flags</parameter> constants</title>
2007-06-15 19:01:57 +00:00
<tgroup cols= "2" >
<thead >
<row >
<entry > Constant Name</entry>
<entry > Description</entry>
</row>
</thead>
<tbody >
<row >
<entry > <constant > ENT_COMPAT</constant> </entry>
<entry > Will convert double-quotes and leave single-quotes alone.</entry>
</row>
<row >
<entry > <constant > ENT_QUOTES</constant> </entry>
<entry > Will convert both double and single quotes.</entry>
</row>
<row >
<entry > <constant > ENT_NOQUOTES</constant> </entry>
<entry > Will leave both double and single quotes unconverted.</entry>
</row>
2010-10-11 01:15:45 +00:00
<row >
<entry > <constant > ENT_IGNORE</constant> </entry>
<entry >
Silently discard invalid code unit sequences instead of returning
2012-01-27 20:42:48 +00:00
an empty string. Using this flag is discouraged as it
<link xlink:href= "&url.delete.nonchars;" > may have security implications</link> .
2010-10-11 01:15:45 +00:00
</entry>
</row>
2011-09-17 11:32:28 +00:00
<row >
<entry > <constant > ENT_SUBSTITUTE</constant> </entry>
<entry >
2012-03-13 22:02:26 +00:00
Replace invalid code unit sequences with a Unicode Replacement Character
U+FFFD (UTF-8) or & #FFFD; (otherwise) instead of returning an empty string.
2011-09-17 11:32:28 +00:00
</entry>
</row>
<row >
<entry > <constant > ENT_DISALLOWED</constant> </entry>
<entry >
2012-03-13 22:02:26 +00:00
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.
2011-09-17 11:32:28 +00:00
</entry>
</row>
<row >
<entry > <constant > ENT_HTML401</constant> </entry>
<entry >
Handle code as HTML 4.01.
</entry>
</row>
<row >
<entry > <constant > ENT_XML1</constant> </entry>
<entry >
Handle code as XML 1.
</entry>
</row>
<row >
<entry > <constant > ENT_XHTML</constant> </entry>
<entry >
Handle code as XHTML.
</entry>
</row>
<row >
<entry > <constant > ENT_HTML5</constant> </entry>
<entry >
Handle code as HTML 5.
</entry>
</row>
2007-06-15 19:01:57 +00:00
</tbody>
</tgroup>
</table>
</para>
</listitem>
</varlistentry>
<varlistentry >
2012-02-16 23:55:01 +00:00
<term > <parameter > encoding</parameter> </term>
2007-06-15 19:01:57 +00:00
<listitem >
2014-08-28 03:36:23 +00:00
&strings.parameter.encoding;
2007-06-15 19:01:57 +00:00
&reference.strings.charsets;
</listitem>
</varlistentry>
<varlistentry >
<term > <parameter > double_encode</parameter> </term>
<listitem >
<para >
When <parameter > double_encode</parameter> is turned off PHP will not
encode existing html entities. The default is to convert everything.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role= "returnvalues" >
&reftitle.returnvalues;
<para >
Returns the encoded string.
</para>
2012-01-27 20:42:48 +00:00
<para >
If the input <parameter > string</parameter> contains an invalid code unit
2012-02-16 23:55:01 +00:00
sequence within the given <parameter > encoding</parameter> an empty string
2012-01-27 20:42:48 +00:00
will be returned, unless either the <constant > ENT_IGNORE</constant> or
<constant > ENT_SUBSTITUTE</constant> flags are set.
</para>
2007-06-15 19:01:57 +00:00
</refsect1>
2020-12-05 14:30:42 +00:00
<refsect1 role= "changelog" >
&reftitle.changelog;
<informaltable >
<tgroup cols= "2" >
<thead >
<row >
<entry > &Version; </entry>
<entry > &Description; </entry>
</row>
</thead>
<tbody >
2021-09-23 13:00:33 +00:00
<row >
<entry > 8.1.0</entry>
<entry >
2021-10-27 08:50:38 +00:00
<parameter > flags</parameter> changed from <constant > ENT_COMPAT</constant> to <constant > ENT_QUOTES</constant> | <constant > ENT_SUBSTITUTE</constant> | <constant > ENT_HTML401</constant> .
2021-09-23 13:00:33 +00:00
</entry>
</row>
2020-12-05 14:30:42 +00:00
<row >
<entry > 8.0.0</entry>
<entry >
<parameter > encoding</parameter> is nullable now.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
2007-06-15 19:01:57 +00:00
<refsect1 role= "examples" >
&reftitle.examples;
2007-06-15 19:01:26 +00:00
<para >
<example >
<title > A <function > htmlentities</function> example</title>
<programlisting role= "php" >
2003-07-24 09:13:45 +00:00
< ![CDATA[
< ?php
$str = "A 'quote' is <b > bold</b> ";
// Outputs: A 'quote' is < b> bold< /b>
echo htmlentities($str);
// Outputs: A ' quote' is < b> bold< /b>
echo htmlentities($str, ENT_QUOTES);
?>
2010-10-11 01:15:45 +00:00
]]>
</programlisting>
</example>
</para>
<para >
<example >
<title > Usage of <constant > ENT_IGNORE</constant> </title>
<programlisting role= "php" >
< ![CDATA[
< ?php
$str = "\x8F!!!";
// Outputs an empty string
2010-12-16 12:10:03 +00:00
echo htmlentities($str, ENT_QUOTES, "UTF-8");
2010-10-11 01:15:45 +00:00
// Outputs "!!!"
2010-12-16 12:10:03 +00:00
echo htmlentities($str, ENT_QUOTES | ENT_IGNORE, "UTF-8");
2010-10-11 01:15:45 +00:00
?>
2003-07-24 09:13:45 +00:00
]]>
2007-06-15 19:01:26 +00:00
</programlisting>
</example>
</para>
2007-06-15 19:01:57 +00:00
</refsect1>
<refsect1 role= "seealso" >
&reftitle.seealso;
2007-06-15 19:01:26 +00:00
<para >
2007-06-15 19:01:57 +00:00
<simplelist >
<member > <function > html_entity_decode</function> </member>
<member > <function > get_html_translation_table</function> </member>
<member > <function > htmlspecialchars</function> </member>
<member > <function > nl2br</function> </member>
<member > <function > urlencode</function> </member>
</simplelist>
2007-06-15 19:01:26 +00:00
</para>
</refsect1>
2007-06-15 19:01:57 +00:00
2007-06-15 19:01:26 +00:00
</refentry>
2002-04-15 00:12:54 +00:00
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
2009-09-25 07:04:39 +00:00
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
2002-04-15 00:12:54 +00:00
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->