<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.url.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.urlencode.php',
    1 => 'urlencode',
    2 => 'URL-encodes string',
  ),
  'up' => 
  array (
    0 => 'ref.url.php',
    1 => 'URL Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.urldecode.php',
    1 => 'urldecode',
  ),
  'next' => 
  array (
    0 => 'book.v8js.php',
    1 => 'V8js',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/url/functions/urlencode.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.urlencode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">urlencode</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">urlencode</span> &mdash; <span class="dc-title">URL-encodes string</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.urlencode-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>urlencode</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="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   This function is convenient when encoding a string to be used in a query
   part of a URL, as a convenient way to pass variables to the next page.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.urlencode-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       The string to be encoded.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.urlencode-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Returns a string in which all non-alphanumeric characters except
   <code class="literal">-_.</code> have been replaced with a percent
   (<code class="literal">%</code>) sign followed by two hex digits and spaces encoded
   as plus (<code class="literal">+</code>) signs.  It is encoded the same way that the
   posted data from a WWW form is encoded, that is the same way as in
   <code class="literal">application/x-www-form-urlencoded</code> media type. This
   differs from the <a href="https://datatracker.ietf.org/doc/html/rfc3986" class="link external">&raquo;&nbsp;RFC 3986</a> encoding (see
   <span class="function"><a href="function.rawurlencode.php" class="function">rawurlencode()</a></span>) in that for historical reasons, spaces
   are encoded as plus (+) signs.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.urlencode-examples">
  <h3 class="title">Esempi</h3> 
  <p class="para">  
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>urlencode()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$userinput </span><span style="color: #007700">= </span><span style="color: #DD0000">'Data123!@-_ +'</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">"UserInput: </span><span style="color: #0000BB">$userinput</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">'&lt;a href="mycgi?foo='</span><span style="color: #007700">, </span><span style="color: #0000BB">urlencode</span><span style="color: #007700">(</span><span style="color: #0000BB">$userinput</span><span style="color: #007700">), </span><span style="color: #DD0000">'"&gt;'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">UserInput: Data123!@-_ +
&lt;a href=&quot;mycgi?foo=Data123%21%40-_+%2B&quot;&gt;</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Example #2 <span class="function"><strong>urlencode()</strong></span> and <span class="function"><a href="function.htmlentities.php" class="function">htmlentities()</a></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$foo </span><span style="color: #007700">= </span><span style="color: #DD0000">'Data123!@-_ +'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bar </span><span style="color: #007700">= </span><span style="color: #DD0000">"Not the same content as </span><span style="color: #0000BB">$foo</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">"foo: </span><span style="color: #0000BB">$foo</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">"bar: </span><span style="color: #0000BB">$bar</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$query_string </span><span style="color: #007700">= </span><span style="color: #DD0000">'foo=' </span><span style="color: #007700">. </span><span style="color: #0000BB">urlencode</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">) . </span><span style="color: #DD0000">'&amp;bar=' </span><span style="color: #007700">. </span><span style="color: #0000BB">urlencode</span><span style="color: #007700">(</span><span style="color: #0000BB">$bar</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">'&lt;a href="mycgi?' </span><span style="color: #007700">. </span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$query_string</span><span style="color: #007700">) . </span><span style="color: #DD0000">'"&gt;'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">foo: Data123!@-_ +
bar: Not the same content as Data123!@-_ +
&lt;a href=&quot;mycgi?foo=Data123%21%40-_+%2B&amp;amp;bar=Not+the+same+content+as+Data123%21%40-_+%2B&quot;&gt;</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.urlencode-notes">
  <h3 class="title">Note</h3>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
    Be careful about variables that may match HTML entities. Things like
    &amp;amp, &amp;copy and &amp;pound are parsed by the browser and the
    actual entity is used instead of the desired variable name.  This is an
    obvious hassle that the W3C has been telling people about for years.
    The reference is here: <a href="http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2" class="link external">&raquo;&nbsp;http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2</a>.
   </p>
   <p class="para">
    PHP supports changing the argument separator to the W3C-suggested
    semi-colon through the arg_separator .ini directive.  Unfortunately most
    user agents do not send form data in this semi-colon separated format.
    A more portable way around this is to use &amp;amp; instead of &amp; as
    the separator.  You don&#039;t need to change PHP&#039;s arg_separator for this.
    Leave it as &amp;, but simply encode your URLs using
    <span class="function"><a href="function.htmlentities.php" class="function">htmlentities()</a></span> or 
    <span class="function"><a href="function.htmlspecialchars.php" class="function">htmlspecialchars()</a></span>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.urlencode-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.urldecode.php" class="function" rel="rdfs-seeAlso">urldecode()</a> - Decodes URL-encoded string</span></li>
    <li><span class="function"><a href="function.htmlentities.php" class="function" rel="rdfs-seeAlso">htmlentities()</a> - Converte tutti i possibili caratteri in entit&agrave; HTML</span></li>
    <li><span class="function"><a href="function.rawurlencode.php" class="function" rel="rdfs-seeAlso">rawurlencode()</a> - URL-encode according to RFC 3986</span></li>
    <li><span class="function"><a href="function.rawurldecode.php" class="function" rel="rdfs-seeAlso">rawurldecode()</a> - Decode URL-encoded strings</span></li>
    <li><a href="https://datatracker.ietf.org/doc/html/rfc3986" class="link external">&raquo;&nbsp;RFC 3986</a></li>
   </ul>
  </p>
 </div>


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