<?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 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.htmlentities.php',
    1 => 'htmlentities',
    2 => 'Convertit tous les caract&egrave;res &eacute;ligibles en entit&eacute;s HTML',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'Fonctions sur les cha&icirc;nes de caract&egrave;res',
  ),
  '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' => 'fr',
    '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">Convertit tous les caractères éligibles en entités HTML</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.htmlentities-description">
  <h3 class="title">Description</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">
   <span class="function"><strong>htmlentities()</strong></span> est identique à la fonction
   <span class="function"><a href="function.htmlspecialchars.php" class="function">htmlspecialchars()</a></span>, sauf que tous les caractères
   qui ont des équivalents en entités HTML sont effectivement
   traduits.
   La fonction <span class="function"><a href="function.get-html-translation-table.php" class="function">get_html_translation_table()</a></span> peut être utilisée
   pour retourner la table de traduction utilisée
   en fonction des constantes <code class="parameter">flags</code> fournies.
  </p>
  <p class="para">
   Pour réaliser l&#039;opération inverse, il faut utiliser 
   la fonction <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">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       La chaîne d&#039;entrée.
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       Un masque d&#039;un ou plusieurs drapeaux suivants, qui déterminent la façon
       dont les guillemets seront gérés, dont les séquences de code invalide seront
       gérées ainsi que le type du document utilisé. Par défaut, c&#039;est
       <code class="literal">ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401</code>.
       <table class="doctable table">
        <caption><strong>Constantes disponibles pour <code class="parameter">flags</code></strong></caption>
        
         <thead>
          <tr>
           <th>Constante</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>Convertit les guillemets doubles, et ignore les guillemets simples.</td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-quotes">ENT_QUOTES</a></code></strong></td>
           <td>Convertit les guillemets doubles et les guillemets simples.</td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-noquotes">ENT_NOQUOTES</a></code></strong></td>
           <td>Ignore les guillemets doubles et les guillemets simples.</td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-ignore">ENT_IGNORE</a></code></strong></td>
           <td>
            Ignore les séquences de caractères invalides plutôt que de retourner une
            chaîne vide. L&#039;utilisation de ce drapeau est fortement
            déconseillée pour des
            <a href="http://unicode.org/reports/tr36/#Deletion_of_Noncharacters" class="link external">&raquo;&nbsp;raisons de sécurité</a>.
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-substitute">ENT_SUBSTITUTE</a></code></strong></td>
           <td>
            Remplace les séquences de code invalide avec un caractère de remplacement
            Unicode U+FFFD (UTF-8) ou &amp;#FFFD; (sinon) au lieu de retourner une
            chaîne vide.
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-disallowed">ENT_DISALLOWED</a></code></strong></td>
           <td>
            Remplace les points du code invalides du document fourni avec
            un caractère de remplacement Unicode U+FFFD (UTF-8) ou &amp;#FFFD;
            (sinon) au lieu du laisser tel quel. Ceci peut être utile pour,
            par exemple, s&#039;assurer du bon formatage de documents XML contenant
            du contenu externe.
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-html401">ENT_HTML401</a></code></strong></td>
           <td>
            Gère le code comme étant du HTML 4.01.
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-xml1">ENT_XML1</a></code></strong></td>
           <td>
            Gère le code comme étant du XML 1.
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-xhtml">ENT_XHTML</a></code></strong></td>
           <td>
            Gère le code comme étant du XHTML.
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-html5">ENT_HTML5</a></code></strong></td>
           <td>
            Gère le code comme étant du HTML 5.
           </td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>
    
    
     <dt><code class="parameter">encoding</code></dt>
     <dd>
      
<p class="para">
Un argument optionnel définissant l&#039;encodage utilisé lors
de la conversion des caractères.
</p>

<p class="para">
Si omis, la valeur par défaut du paramètre <code class="parameter">encoding</code>
est la valeur de l&#039;option de configuration
<a href="ini.core.php#ini.default-charset" class="link">default_charset</a>.
</p>

<p class="para">
Malgré le fait que cet argument soit techniquement optionnel, vous
êtes vivement encouragé à spécifier la valeur correcte pour votre code
si l&#039;option de configuration
<a href="ini.core.php#ini.default-charset" class="link">default_charset</a>
a été définie de façon incorrecte pour l&#039;entrée fournie.
</p>

      




<p class="para">
 Les jeux de caractères suivants sont supportés :
 <table class="doctable table">
  <caption><strong>Jeux de caractères supportés</strong></caption>
  
   <thead>
    <tr>
     <th>Jeux de caractères</th>
     <th>Alias</th>
     <th>Description</th>
    </tr>

   </thead>

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

    <tr>
     <td>ISO-8859-5</td>
     <td>ISO8859-5</td>
     <td>
      Jeu de caractères cyrillique rarement utilisé
      (Latin/Cyrillic).
     </td>
    </tr>

    <tr>
     <td>ISO-8859-15</td>
     <td>ISO8859-15</td>
     <td>
      Europe occidentale, Latin-9. Dispose du signe Euro, des caractères
      spéciaux français et finlandais, qui manquent au Latin-1 (ISO-8859-1).
     </td>
    </tr>

    <tr>
     <td>UTF-8</td>
     <td class="empty">&nbsp;</td>
     <td>
      Unicode 8 bits multioctets, compatible avec l&#039;ASCII
     </td>
    </tr>

    <tr>
     <td>cp866</td>
     <td>ibm866, 866</td>
     <td>
      Jeu de caractères Cyrillique spécifique à DOS.
     </td>
    </tr>

    <tr>
     <td>cp1251</td>
     <td>Windows-1251, win-1251, 1251</td>
     <td>
      Jeu de caractères cyrillique spécifique à Windows.
     </td>
    </tr>

    <tr>
     <td>cp1252</td>
     <td>Windows-1252, 1252</td>
     <td>
      Jeu de caractères spécifique de Windows pour l&#039;Europe occidentale.
     </td>
    </tr>

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

    <tr>
     <td>BIG5</td>
     <td>950</td>
     <td>
      Chinois traditionnel, principalement utilisé à Taïwan.
     </td>
    </tr>

    <tr>
     <td>GB2312</td>
     <td>936</td>
     <td>
      Chinois simplifié, officiel.
     </td>
    </tr>

    <tr>
     <td>BIG5-HKSCS</td>
     <td class="empty">&nbsp;</td>
     <td>
      Big5 avec les extensions de Hong Kong, chinois traditionnel.
     </td>
    </tr>

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

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

    <tr>
     <td>MacRoman</td>
     <td class="empty">&nbsp;</td>
     <td>
      Jeu de caractères utilisé par Mac OS.
     </td>
    </tr>

    <tr>
     <td><code class="literal">&#039;&#039;</code></td>
     <td class="empty">&nbsp;</td>
     <td>
      Une chaîne vide active la détection de l&#039;encodage depuis un script (multioctet
      Zend), <a href="ini.core.php#ini.default-charset" class="link">default_charset</a> et la locale
      courante (voir <span class="function"><a href="function.nl-langinfo.php" class="function">nl_langinfo()</a></span> et
      <span class="function"><a href="function.setlocale.php" class="function">setlocale()</a></span>), dans cet ordre. Non recommandé.
     </td>
    </tr>

   </tbody>
  
 </table>

<blockquote class="note"><p><strong class="note">Note</strong>: 
 <span class="simpara">
  Les autres jeux de caractères ne sont pas reconnus. L&#039;encodage par défaut
  sera utilisé à la place et une alerte sera émise.
 </span>
</p></blockquote>
</p>


     </dd>
    
    
     <dt><code class="parameter">double_encode</code></dt>
     <dd>
      <p class="para">
       Lorsque <code class="parameter">double_encode</code> est désactivé, PHP n&#039;encodera pas
       les entités html existantes. Par défaut, tout est converti.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.htmlentities-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne la chaîne encodée.
  </p>
  <p class="para">
   Si l&#039;entrée <code class="parameter">string</code> contient une séquence de
   code invalide dans l&#039;encodage <code class="parameter">encoding</code>
   fourni, une chaîne vide sera retournée, à moins que le drapeau
   <strong><code><a href="string.constants.php#constant.ent-ignore">ENT_IGNORE</a></code></strong> ou le drapeau
   <strong><code><a href="string.constants.php#constant.ent-substitute">ENT_SUBSTITUTE</a></code></strong> ne soit défini.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.htmlentities-changelog">
  <h3 class="title">Historique</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.1.0</td>
      <td>
       <code class="parameter">flags</code> a changé de <strong><code><a href="string.constants.php#constant.ent-compat">ENT_COMPAT</a></code></strong> à
       <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> est désormais nullable.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.htmlentities-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <span class="function"><strong>htmlentities()</strong></span></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">'Un \'apostrophe\' en &lt;b&gt;gras&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>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Un &amp;#039;apostrophee&amp;#039; est &amp;lt;b&amp;gt;gras&amp;lt;/b&amp;gt;

Un &#039;apostrophe&#039; est &amp;lt;b&amp;gt;gras&amp;lt;/b&amp;gt</pre>
</div>
    </div>
   </div>
  </p>
  
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Exemple #2 Utilisation de <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">// Affiche une chaine vide<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">// Affiche "!!!"<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">Voir aussi</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> - Convertit les entit&eacute;s HTML &agrave; leurs caract&egrave;res correspondant</span></li>
    <li><span class="function"><a href="function.get-html-translation-table.php" class="function" rel="rdfs-seeAlso">get_html_translation_table()</a> - Retourne la table de traduction des entit&eacute;s utilis&eacute;e par htmlspecialchars et htmlentities</span></li>
    <li><span class="function"><a href="function.htmlspecialchars.php" class="function" rel="rdfs-seeAlso">htmlspecialchars()</a> - Convertit les caract&egrave;res sp&eacute;ciaux en entit&eacute;s HTML</span></li>
    <li><span class="function"><a href="function.nl2br.php" class="function" rel="rdfs-seeAlso">nl2br()</a> - Ins&egrave;re un retour &agrave; la ligne HTML &agrave; chaque nouvelle ligne</span></li>
    <li><span class="function"><a href="function.urlencode.php" class="function" rel="rdfs-seeAlso">urlencode()</a> - Encode une cha&icirc;ne en URL</span></li>
   </ul>
  </p>
 </div>


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