<?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 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.htmlspecialchars.php',
    1 => 'htmlspecialchars',
    2 => 'Converte i caratteri speciali in entit&agrave; HTML',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.htmlentities.php',
    1 => 'htmlentities',
  ),
  'next' => 
  array (
    0 => 'function.htmlspecialchars-decode.php',
    1 => 'htmlspecialchars_decode',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    'path' => 'reference/strings/functions/htmlspecialchars.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.htmlspecialchars" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">htmlspecialchars</h1> 
    <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">htmlspecialchars</span> &mdash; <span class="dc-title">
     Converte i caratteri speciali in entità HTML
    </span></p>

   </div>
   <div class="refsect1 unknown-1300" id="refsect1-function.htmlspecialchars-unknown-1300">
    <h3 class="title">Descrizione</h3>
     <div class="methodsynopsis dc-description">
      <span class="methodname"><strong>htmlspecialchars</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$quote_style</code><span class="initializer"> = ?</span></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$charset</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

    <p class="para rdfs-comment">
     Alcuni caratteri hanno significati particolari in HTML, e, per questo,
     devono essere rappresentati tramite entità HTML, se devono mantenere il proprio
     significato. Questa funzione restituisce restituisce una stringa con
     la conversione di alcuni di questi caratteri; la conversione svolta non è
     sempre valida nell&#039;ambito della programmazione web. Se occorre l&#039;utilizzo
     di tutte le entità HTML, utilizzare
     <span class="function"><a href="function.htmlentities.php" class="function">htmlentities()</a></span>.
    </p>
    <p class="simpara">
     Questa funzione è utile nel prevenire la presenza di marcatori
     HTML negli input utente, tipo nei forum o nei guest book.
     Il secondo parametro <code class="parameter">quote_style</code>, opzionale,
     indica alla funzione come comportarsi con gli apici singoli e doppi.
     La modalità di default è, <strong><code><a href="string.constants.php#constant.ent-compat">ENT_COMPAT</a></code></strong>; questa modalità è compatibile con il passato
     e traduce solo gli apici doppi lasciando inalterati gli apici singoli.
     Se si imposta <strong><code><a href="string.constants.php#constant.ent-quotes">ENT_QUOTES</a></code></strong>, entrambi i tipi di apici, singoli e doppi,
     sono convertiti in entità e, infine, se si utilizza <strong><code><a href="string.constants.php#constant.ent-noquotes">ENT_NOQUOTES</a></code></strong> ne gli apici singoli
     ne gli apici doppi sono convertiti in entità.
    </p>
    <p class="para">
     La conversioni applicate sono:
     <ul class="itemizedlist">
      <li class="listitem">
       <span class="simpara">
        &#039;&amp;&#039; (e commerciale) diventa &#039;&amp;amp;&#039;
       </span>
      </li>
      <li class="listitem">
       <span class="simpara">
        &#039;&quot;&#039; (doppio apice) diventa &#039;&amp;quot;&#039; con <strong><code><a href="string.constants.php#constant.ent-noquotes">ENT_NOQUOTES</a></code></strong>
        is not set.
       </span>
      </li>
      <li class="listitem">
       <span class="simpara">
        &#039;&#039;&#039; (singolo apice) diventa &#039;&amp;#039;&#039; soltanto con
        l&#039;impostazione di <strong><code><a href="string.constants.php#constant.ent-quotes">ENT_QUOTES</a></code></strong>.
       </span>
      </li>
      <li class="listitem">
       <span class="simpara">
        &#039;&lt;&#039; (minore) diventa &#039;&amp;lt;&#039;
       </span>
      </li>
      <li class="listitem">
       <span class="simpara">
        &#039;&gt;&#039; (maggiore) diventa &#039;&amp;gt;&#039;
       </span>
      </li>
     </ul>
     <div class="example" id="example-1">
      <p><strong>Example #1 Esempio di uso di <span class="function"><strong>htmlspecialchars()</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 />$new </span><span style="color: #007700">= </span><span style="color: #0000BB">htmlspecialchars</span><span style="color: #007700">(</span><span style="color: #DD0000">"&lt;a href='test'&gt;Test&lt;/a&gt;"</span><span style="color: #007700">, </span><span style="color: #0000BB">ENT_QUOTES</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$new</span><span style="color: #007700">; </span><span style="color: #FF8000">// &amp;lt;a href=&amp;#039;test&amp;#039;&amp;gt;Test&amp;lt;/a&amp;gt;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
      </div>

     </div>
    </p>
    <p class="para">
     Occorre notare che questa funzione non converte null&#039;altro oltre
     ai caratteri elencati in precedenza. Per la conversione di tutte le entità
     fare riferimento a <span class="function"><a href="function.htmlentities.php" class="function">htmlentities()</a></span>. Il secondo parametro
     è stato inserito in PHP 3.0.17 e 4.0.3. 
    </p>
    <p class="para">
     Il terzo parametro <code class="parameter">charset</code> indica quale set di caratteri utilizzare
     nella conversione. Il set di caratteri di default è ISO-8859-1. Questo terzo
     parametro è stato aggiunto in PHP 4.1.0.
    </p>
    


<p class="para">
 Elenco dei set di caratteri supportati:
 <table class="doctable table">
  <caption><strong>Set di caratteri supportati</strong></caption>
  
   <thead>
    <tr>
     <th>Set di caratteri</th>
     <th>Alias</th>
     <th>Descrizione</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>
      Il charset cirillico poco utilizzato (Latin/Cyrillic).
     </td>
    </tr>

    <tr>
     <td>ISO-8859-15</td>
     <td>ISO8859-15</td>
     <td>
      Western European, Latin-9. Con in più il simbolo dell&#039;Euro e i caratteri francesi 
      e finnici mancanti in Latin-1 (ISO-8859-1).
     </td>
    </tr>

    <tr>
     <td>UTF-8</td>
     <td class="empty">&nbsp;</td>
     <td>
      Set ASCII compatibile con il set multi-byte Unicode su 8-bit.
     </td>
    </tr>

    <tr>
     <td>cp866</td>
     <td>ibm866, 866</td>
     <td>
      Set di caratteri cirillico specifico del Dos.
     </td>
    </tr>

    <tr>
     <td>cp1251</td>
     <td>Windows-1251, win-1251, 1251</td>
     <td>
      Set di caratteri cirillico specifico di Windows.
     </td>
    </tr>

    <tr>
     <td>cp1252</td>
     <td>Windows-1252, 1252</td>
     <td>
      Set di caratteri specifico di Windows per l&#039;Europa occidentale.
     </td>
    </tr>

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

    <tr>
     <td>BIG5</td>
     <td>950</td>
     <td>
      Cinese tradizionale, usato principalmente a Taiwan.
     </td>
    </tr>

    <tr>
     <td>GB2312</td>
     <td>936</td>
     <td>
      Cinese semplificato, set di caratteri nazionale standard.
     </td>
    </tr>

    <tr>
     <td>BIG5-HKSCS</td>
     <td class="empty">&nbsp;</td>
     <td>
      Big5 con estensioni per Hong Kong, cinese tradizionale.
     </td>
    </tr>

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

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

    <tr>
     <td>MacRoman</td>
     <td class="empty">&nbsp;</td>
     <td>
      Charset che veniva utilizzato dal Mac OS.
     </td>
    </tr>

    <tr>
     <td><code class="literal">&#039;&#039;</code></td>
     <td class="empty">&nbsp;</td>
     <td>
      Una stringa vuota attiva il rilevamento della codifica dallo script (Zend multibyte),
      <a href="ini.core.php#ini.default-charset" class="link">default_charset</a> e l&#039;attuale
      locale (guarda <span class="function"><a href="function.nl-langinfo.php" class="function">nl_langinfo()</a></span> e
      <span class="function"><a href="function.setlocale.php" class="function">setlocale()</a></span>), in quest&#039;ordine. Non consigliato.
     </td>
    </tr>

   </tbody>
  
 </table>

 <blockquote class="note"><p><strong class="note">Nota</strong>: 
  <span class="simpara">
   Ogni altro set di caratteri non è riconosciuto. Sarà invece utilizzata la codifica
   predefinita e verrà mostrato un avviso.
  </span>
 </p></blockquote>
</p>


    <p class="para">
     Vedere anche <span class="function"><a href="function.get-html-translation-table.php" class="function">get_html_translation_table()</a></span>,
     <span class="function"><a href="function.strip-tags.php" class="function">strip_tags()</a></span>,
     <span class="function"><a href="function.htmlentities.php" class="function">htmlentities()</a></span> e <span class="function"><a href="function.nl2br.php" class="function">nl2br()</a></span>.
    </p>
   </div>

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