<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.htmlentities.php',
    1 => 'htmlentities',
    2 => 'Convert all applicable characters to HTML entities',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String Функції',
  ),
  'prev' => 
  array (
    0 => 'function.html-entity-decode.php',
    1 => 'html_entity_decode',
  ),
  'next' => 
  array (
    0 => 'function.htmlspecialchars.php',
    1 => 'htmlspecialchars',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/strings/functions/htmlentities.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.htmlentities" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">htmlentities</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">htmlentities</span> &mdash; <span class="dc-title">Convert all applicable characters to HTML entities</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.htmlentities-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>htmlentities</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$encoding</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$double_encode</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong></span></span><br>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   This function is identical to <span class="function"><a href="function.htmlspecialchars.php" class="function">htmlspecialchars()</a></span> in all
   ways, except with <span class="function"><strong>htmlentities()</strong></span>, all characters which
   have HTML character entity equivalents are translated into these entities.
   The <span class="function"><a href="function.get-html-translation-table.php" class="function">get_html_translation_table()</a></span> function can be used
   to return the translation table used dependent upon the provided
   <code class="parameter">flags</code> constants.
  </p>
  <p class="para">
   If you want to decode instead (the reverse) you can use
   <span class="function"><a href="function.html-entity-decode.php" class="function">html_entity_decode()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.htmlentities-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       The input string.
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       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
       <code class="literal">ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401</code>.
       <table class="doctable table">
        <caption><strong>Available <code class="parameter">flags</code> constants</strong></caption>
        
         <thead>
          <tr>
           <th>Constant Name</th>
           <th>Description</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-compat">ENT_COMPAT</a></code></strong></td>
           <td>Will convert double-quotes and leave single-quotes alone.</td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-quotes">ENT_QUOTES</a></code></strong></td>
           <td>Will convert both double and single quotes.</td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-noquotes">ENT_NOQUOTES</a></code></strong></td>
           <td>Will leave both double and single quotes unconverted.</td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-ignore">ENT_IGNORE</a></code></strong></td>
           <td>
            Silently discard invalid code unit sequences instead of returning
            an empty string. Using this flag is discouraged as it
            <a href="http://unicode.org/reports/tr36/#Deletion_of_Noncharacters" class="link external">&raquo;&nbsp;may have security implications</a>.
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-substitute">ENT_SUBSTITUTE</a></code></strong></td>
           <td>
            Replace invalid code unit sequences with a Unicode Replacement Character
            U+FFFD (UTF-8) or &amp;#FFFD; (otherwise) instead of returning an empty string.
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-disallowed">ENT_DISALLOWED</a></code></strong></td>
           <td>
            Replace invalid code points for the given document type with a
            Unicode Replacement Character U+FFFD (UTF-8) or &amp;#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.
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-html401">ENT_HTML401</a></code></strong></td>
           <td>
            Handle code as HTML 4.01.
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-xml1">ENT_XML1</a></code></strong></td>
           <td>
            Handle code as XML 1.
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-xhtml">ENT_XHTML</a></code></strong></td>
           <td>
            Handle code as XHTML.
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-html5">ENT_HTML5</a></code></strong></td>
           <td>
            Handle code as HTML 5.
           </td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>
    
    
     <dt><code class="parameter">encoding</code></dt>
     <dd>
      
 <p class="para">
  Необов&#039;язковий параметр. Ним вказується кодування, що застосовуватиметься
  під час перетворення символів.
 </p>

 <p class="para">
  Якщо пропущено, то параметр <code class="parameter">encoding</code> отримає значення
  директиви <a href="ini.core.php#ini.default-charset" class="link">default_charset</a>.
 </p>

 <p class="para">
  Хоча технічно цей аргумент є необов&#039;язковим, але рекомендується вказати
  в коді потрібне значення, оскільки директива <a href="ini.core.php#ini.default-charset" class="link">default_charset</a> може бути неправильною
  для заданих вхідних даних.
 </p>

      

<p class="para">
 The following character sets are supported:
 <table class="doctable table">
  <caption><strong>Supported charsets</strong></caption>
  
   <thead>
    <tr>
     <th>Charset</th>
     <th>Aliases</th>
     <th>Description</th>
    </tr>

   </thead>

   <tbody class="tbody">
    <tr>
     <td>ISO-8859-1</td>
     <td>ISO8859-1</td>
     <td>
      Western European, Latin-1.
     </td>
    </tr>

    <tr>
     <td>ISO-8859-5</td>
     <td>ISO8859-5</td>
     <td>
      Little used cyrillic charset (Latin/Cyrillic).
     </td>
    </tr>

    <tr>
     <td>ISO-8859-15</td>
     <td>ISO8859-15</td>
     <td>
      Western European, Latin-9. Adds the Euro sign, French and Finnish
      letters missing in Latin-1 (ISO-8859-1).
     </td>
    </tr>

    <tr>
     <td>UTF-8</td>
     <td class="empty">&nbsp;</td>
     <td>
      ASCII compatible multi-byte 8-bit Unicode.
     </td>
    </tr>

    <tr>
     <td>cp866</td>
     <td>ibm866, 866</td>
     <td>
      DOS-specific Cyrillic charset.
     </td>
    </tr>

    <tr>
     <td>cp1251</td>
     <td>Windows-1251, win-1251, 1251</td>
     <td>
      Windows-specific Cyrillic charset.
     </td>
    </tr>

    <tr>
     <td>cp1252</td>
     <td>Windows-1252, 1252</td>
     <td>
      Windows specific charset for Western European.
     </td>
    </tr>

    <tr>
     <td>KOI8-R</td>
     <td>koi8-ru, koi8r</td>
     <td>
      Russian.
     </td>
    </tr>

    <tr>
     <td>BIG5</td>
     <td>950</td>
     <td>
      Traditional Chinese, mainly used in Taiwan.
     </td>
    </tr>

    <tr>
     <td>GB2312</td>
     <td>936</td>
     <td>
      Simplified Chinese, national standard character set.
     </td>
    </tr>

    <tr>
     <td>BIG5-HKSCS</td>
     <td class="empty">&nbsp;</td>
     <td>
      Big5 with Hong Kong extensions, Traditional Chinese.
     </td>
    </tr>

    <tr>
     <td>Shift_JIS</td>
     <td>SJIS, SJIS-win, cp932, 932</td>
     <td>
      Japanese
     </td>
    </tr>

    <tr>
     <td>EUC-JP</td>
     <td>EUCJP, eucJP-win</td>
     <td>
      Japanese
     </td>
    </tr>

    <tr>
     <td>MacRoman</td>
     <td class="empty">&nbsp;</td>
     <td>
      Charset that was used by Mac OS.
     </td>
    </tr>

    <tr>
     <td><code class="literal">&#039;&#039;</code></td>
     <td class="empty">&nbsp;</td>
     <td>
      An empty string activates detection from script encoding (Zend multibyte),
      <a href="ini.core.php#ini.default-charset" class="link">default_charset</a> and current
      locale (see <span class="function"><a href="function.nl-langinfo.php" class="function">nl_langinfo()</a></span> and
      <span class="function"><a href="function.setlocale.php" class="function">setlocale()</a></span>), in this order. Not recommended.
     </td>
    </tr>

   </tbody>
  
 </table>

 <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
  <span class="simpara">
   Any other character sets are not recognized. The default encoding will be
   used instead and a warning will be emitted.
  </span>
 </p></blockquote>
</p>


     </dd>
    
    
     <dt><code class="parameter">double_encode</code></dt>
     <dd>
      <p class="para">
       When <code class="parameter">double_encode</code> is turned off PHP will not
       encode existing html entities. The default is to convert everything.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.htmlentities-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns the encoded string.
  </p>
  <p class="para">
   If the input <code class="parameter">string</code> contains an invalid code unit
   sequence within the given <code class="parameter">encoding</code> an empty string
   will be returned, unless either the <strong><code><a href="string.constants.php#constant.ent-ignore">ENT_IGNORE</a></code></strong> or
   <strong><code><a href="string.constants.php#constant.ent-substitute">ENT_SUBSTITUTE</a></code></strong> flags are set.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.htmlentities-changelog">
  <h3 class="title">Журнал змін</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Версія</th>
      <th>Опис</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.1.0</td>
      <td>
       <code class="parameter">flags</code> changed from <strong><code><a href="string.constants.php#constant.ent-compat">ENT_COMPAT</a></code></strong> to <strong><code><a href="string.constants.php#constant.ent-quotes">ENT_QUOTES</a></code></strong> | <strong><code><a href="string.constants.php#constant.ent-substitute">ENT_SUBSTITUTE</a></code></strong> | <strong><code><a href="string.constants.php#constant.ent-html401">ENT_HTML401</a></code></strong>.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">encoding</code> is nullable now.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.htmlentities-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 A <span class="function"><strong>htmlentities()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$str </span><span style="color: #007700">= </span><span style="color: #DD0000">"A 'quote' is &lt;b&gt;bold&lt;/b&gt;"</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"\n\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">, </span><span style="color: #0000BB">ENT_COMPAT</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">A &amp;#039;quote&amp;#039; is &amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;

A &#039;quote&#039; is &amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt</pre>
</div>
    </div>
   </div>
  </p>
  
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Приклад #2 Usage of <strong><code><a href="string.constants.php#constant.ent-ignore">ENT_IGNORE</a></code></strong></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$str </span><span style="color: #007700">= </span><span style="color: #DD0000">"\x8F!!!"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Outputs an empty string<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">, </span><span style="color: #0000BB">ENT_QUOTES</span><span style="color: #007700">, </span><span style="color: #DD0000">"UTF-8"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Outputs "!!!"<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">, </span><span style="color: #0000BB">ENT_QUOTES </span><span style="color: #007700">| </span><span style="color: #0000BB">ENT_IGNORE</span><span style="color: #007700">, </span><span style="color: #DD0000">"UTF-8"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.htmlentities-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.html-entity-decode.php" class="function" rel="rdfs-seeAlso">html_entity_decode()</a> - Convert HTML entities to their corresponding characters</span></li>
    <li><span class="function"><a href="function.get-html-translation-table.php" class="function" rel="rdfs-seeAlso">get_html_translation_table()</a> - Returns the translation table used by htmlspecialchars and htmlentities</span></li>
    <li><span class="function"><a href="function.htmlspecialchars.php" class="function" rel="rdfs-seeAlso">htmlspecialchars()</a> - Convert special characters to HTML entities</span></li>
    <li><span class="function"><a href="function.nl2br.php" class="function" rel="rdfs-seeAlso">nl2br()</a> - Inserts HTML line breaks before all newlines in a string</span></li>
    <li><span class="function"><a href="function.urlencode.php" class="function" rel="rdfs-seeAlso">urlencode()</a> - URL-encodes string</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>