Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 6491

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>URL-encodes string</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.urldecode.html">urldecode</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="book.v8js.html">V8js</a></div>
 <div class="up"><a href="ref.url.html">URL Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.urlencode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">urlencode</h1>
  <p class="verinfo">(PHP 4, PHP 5)</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">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>urlencode</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></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">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">str</code></em></span>
     <dd>

      <p class="para">
       The string to be encoded.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.urlencode-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a string in which all non-alphanumeric characters except
   <em>-_.</em> have been replaced with a percent
   (<em>%</em>) sign followed by two hex digits and spaces encoded
   as plus (<em>+</em>) signs.  It is encoded the same way that the
   posted data from a WWW form is encoded, that is the same way as in
   <em>application/x-www-form-urlencoded</em> media type. This
   differs from the <a href="http://www.faqs.org/rfcs/rfc3986" class="link external">&raquo;&nbsp;RFC 3986</a> encoding (see
    <span class="function"><a href="function.rawurlencode.html" 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">Examples</h3> 
  <p class="para">  
   <div class="example" id="example-4095">
    <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 /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'&lt;a&nbsp;href="mycgi?foo='</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">urlencode</span><span style="color: #007700">(</span><span style="color: #0000BB">$userinput</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">'"&gt;'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-4096">
    <p><strong>Example #2  <span class="function"><strong>urlencode()</strong></span> and  <span class="function"><a href="function.htmlentities.html" 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 />$query_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'foo='&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">urlencode</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">'&amp;bar='&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">urlencode</span><span style="color: #007700">(</span><span style="color: #0000BB">$bar</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;a&nbsp;href="mycgi?'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$query_string</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">'"&gt;'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

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


 <div class="refsect1 notes" id="refsect1-function.urlencode-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</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.html" class="function">htmlentities()</a></span> or 
     <span class="function"><a href="function.htmlspecialchars.html" class="function">htmlspecialchars()</a></span>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.urlencode-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.urldecode.html" class="function" rel="rdfs-seeAlso">urldecode()</a> - Decodes URL-encoded string</span></li>
    <li class="member"> <span class="function"><a href="function.htmlentities.html" class="function" rel="rdfs-seeAlso">htmlentities()</a> - Convert all applicable characters to HTML entities</span></li>
    <li class="member"> <span class="function"><a href="function.rawurlencode.html" class="function" rel="rdfs-seeAlso">rawurlencode()</a> - URL-encode according to RFC 3986</span></li>
    <li class="member"> <span class="function"><a href="function.rawurldecode.html" class="function" rel="rdfs-seeAlso">rawurldecode()</a> - Decode URL-encoded strings</span></li>
    <li class="member"><a href="http://www.faqs.org/rfcs/rfc3986" class="link external">&raquo;&nbsp;RFC 3986</a></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.urldecode.html">urldecode</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="book.v8js.html">V8js</a></div>
 <div class="up"><a href="ref.url.html">URL Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>