Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 703d980c580707c382b4e43e25965bc5 > files > 6760

php-manual-pt_BR-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>http_build_query</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="Manual do PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="URL"
HREF="ref.url.html"><LINK
REL="PREVIOUS"
TITLE="get_meta_tags"
HREF="function.get-meta-tags.html"><LINK
REL="NEXT"
TITLE="parse_url"
HREF="function.parse-url.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Manual do PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.get-meta-tags.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.parse-url.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.http-build-query"
></A
>http_build_query</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN229116"
></A
><P
>    (PHP 5)</P
>http_build_query&nbsp;--&nbsp;Generate URL-encoded query string</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN229119"
></A
><H2
>Descrição</H2
>string <B
CLASS="methodname"
>http_build_query</B
> ( array formdata [, string numeric_prefix [, string arg_separator]] )<BR
></BR
><P
>&#13;   Generates a URL-encoded query string from the associative (or indexed)
   array provided.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN229134"
></A
><H2
>Parâmetros</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>formdata</CODE
></DT
><DD
><P
>&#13;       May be an array or object containing properties.
      </P
><P
>&#13;       The array form may be a simple one-dimensional structure, or an array
       of arrays (who in turn may contain other arrays).
      </P
></DD
><DT
><CODE
CLASS="parameter"
>numeric_prefix</CODE
></DT
><DD
><P
>&#13;       If numeric indices are used in the base array and this parameter is
       provided, it will be prepended to the numeric index for elements in
       the base array only.
      </P
><P
>&#13;       This is meant to allow for legal variable names when the data is
       decoded by PHP or another CGI application later on.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>arg_separator</CODE
></DT
><DD
><P
>&#13;       <A
HREF="ini.core.html#ini.arg-separator.output"
>arg_separator.output</A
>
       is used to separate arguments, unless this parameter is specified,
       and is then used.
      </P
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN229156"
></A
><H2
>Valores de retornado</H2
><P
>&#13;   Returns a URL-encoded string.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN229159"
></A
><H2
>Histórico</H2
><P
>&#13;   <DIV
CLASS="informaltable"
><P
></P
><A
NAME="AEN229162"
></A
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>Versão</TH
><TH
>Descrição</TH
></TR
></THEAD
><TBODY
><TR
><TD
>5.1.2</TD
><TD
>&#13;        The <CODE
CLASS="parameter"
>arg_separator</CODE
> parameter was added.
       </TD
></TR
><TR
><TD
>5.1.3</TD
><TD
>&#13;        Square brackets are escaped.
       </TD
></TR
></TBODY
></TABLE
><P
></P
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN229176"
></A
><H2
>Exemplos</H2
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN229178"
></A
><P
><B
>Exemplo 1. Simple usage of <B
CLASS="function"
>http_build_query()</B
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$data </font><font color="#007700">= array(</font><font color="#DD0000">'foo'</font><font color="#007700">=&gt;</font><font color="#DD0000">'bar'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'baz'</font><font color="#007700">=&gt;</font><font color="#DD0000">'boom'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'cow'</font><font color="#007700">=&gt;</font><font color="#DD0000">'milk'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'php'</font><font color="#007700">=&gt;</font><font color="#DD0000">'hypertext processor'</font><font color="#007700">);<br /><br />echo </font><font color="#0000BB">http_build_query</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">); </font><font color="#FF8000">// foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor<br /></font><font color="#007700">echo </font><font color="#0000BB">http_build_query</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">, </font><font color="#DD0000">'&amp;amp;'</font><font color="#007700">); </font><font color="#FF8000">// foo=bar&amp;amp;baz=boom&amp;amp;cow=milk&amp;amp;php=hypertext+processor<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN229182"
></A
><P
><B
>Exemplo 2. <B
CLASS="function"
>http_build_query()</B
> with numerically index elements.</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$data </font><font color="#007700">= array(</font><font color="#DD0000">'foo'</font><font color="#007700">, </font><font color="#DD0000">'bar'</font><font color="#007700">, </font><font color="#DD0000">'baz'</font><font color="#007700">, </font><font color="#DD0000">'boom'</font><font color="#007700">, </font><font color="#DD0000">'cow' </font><font color="#007700">=&gt; </font><font color="#DD0000">'milk'</font><font color="#007700">, </font><font color="#DD0000">'php' </font><font color="#007700">=&gt;</font><font color="#DD0000">'hypertext processor'</font><font color="#007700">);<br /><br />echo </font><font color="#0000BB">http_build_query</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">) . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br />echo </font><font color="#0000BB">http_build_query</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">, </font><font color="#DD0000">'myvar_'</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>O exemplo acima irá imprimir:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>0=foo&#38;1=bar&#38;2=baz&#38;3=boom&#38;cow=milk&#38;php=hypertext+processor
myvar_0=foo&#38;myvar_1=bar&#38;myvar_2=baz&#38;myvar_3=boom&#38;cow=milk&#38;php=hypertext+processor</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN229188"
></A
><P
><B
>Exemplo 3. <B
CLASS="function"
>http_build_query()</B
> with complex arrays</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$data </font><font color="#007700">= array(</font><font color="#DD0000">'user'</font><font color="#007700">=&gt;array(</font><font color="#DD0000">'name'</font><font color="#007700">=&gt;</font><font color="#DD0000">'Bob Smith'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'age'</font><font color="#007700">=&gt;</font><font color="#0000BB">47</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'sex'</font><font color="#007700">=&gt;</font><font color="#DD0000">'M'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'dob'</font><font color="#007700">=&gt;</font><font color="#DD0000">'5/12/1956'</font><font color="#007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'pastimes'</font><font color="#007700">=&gt;array(</font><font color="#DD0000">'golf'</font><font color="#007700">, </font><font color="#DD0000">'opera'</font><font color="#007700">, </font><font color="#DD0000">'poker'</font><font color="#007700">, </font><font color="#DD0000">'rap'</font><font color="#007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'children'</font><font color="#007700">=&gt;array(</font><font color="#DD0000">'bobby'</font><font color="#007700">=&gt;array(</font><font color="#DD0000">'age'</font><font color="#007700">=&gt;</font><font color="#0000BB">12</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'sex'</font><font color="#007700">=&gt;</font><font color="#DD0000">'M'</font><font color="#007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'sally'</font><font color="#007700">=&gt;array(</font><font color="#DD0000">'age'</font><font color="#007700">=&gt;</font><font color="#0000BB">8</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'sex'</font><font color="#007700">=&gt;</font><font color="#DD0000">'F'</font><font color="#007700">)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'CEO'</font><font color="#007700">);<br /><br />echo </font><font color="#0000BB">http_build_query</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">, </font><font color="#DD0000">'flags_'</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>&#13;    this will output : (word wrapped for readability)
   </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>user%5Bname%5D=Bob+Smith&#38;user%5Bage%5D=47&#38;user%5Bsex%5D=M&#38;
user%5Bdob%5D=5%2F12%2F1956&#38;pastimes%5B0%5D=golf&#38;pastimes%5B1%5D=opera&#38;
pastimes%5B2%5D=poker&#38;pastimes%5B3%5D=rap&#38;children%5Bbobby%5D%5Bage%5D=12&#38;
children%5Bbobby%5D%5Bsex%5D=M&#38;children%5Bsally%5D%5Bage%5D=8&#38;
children%5Bsally%5D%5Bsex%5D=F&#38;flags_0=CEO</PRE
></TD
></TR
></TABLE
><P
>&#13;    <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
      Only the numerically indexed element in the base array "CEO" received a
      prefix.  The other numeric indices, found under pastimes, do not
      require a string prefix to be legal variable names.
     </P
></BLOCKQUOTE
></DIV
>
   </P
></DIV
></TD
></TR
></TABLE
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN229197"
></A
><P
><B
>Exemplo 4. Using <B
CLASS="function"
>http_build_query()</B
> with an object</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">class </font><font color="#0000BB">myClass </font><font color="#007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;var </font><font color="#0000BB">$foo</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;var </font><font color="#0000BB">$baz</font><font color="#007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;function </font><font color="#0000BB">myClass</font><font color="#007700">() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">foo </font><font color="#007700">= </font><font color="#DD0000">'bar'</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">baz </font><font color="#007700">= </font><font color="#DD0000">'boom'</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></font><font color="#0000BB">$data </font><font color="#007700">= new </font><font color="#0000BB">myClass</font><font color="#007700">();<br /><br />echo </font><font color="#0000BB">http_build_query</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">); </font><font color="#FF8000">// foo=bar&amp;baz=boom<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN229201"
></A
><H2
>Veja também</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.parse-str.html"
><B
CLASS="function"
>parse_str()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.parse-url.html"
><B
CLASS="function"
>parse_url()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.urlencode.html"
><B
CLASS="function"
>urlencode()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.array-walk.html"
><B
CLASS="function"
>array_walk()</B
></A
></TD
></TR
></TBODY
></TABLE
><P
></P
>
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.get-meta-tags.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Principal</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.parse-url.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>get_meta_tags</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.url.html"
ACCESSKEY="U"
>Acima</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>parse_url</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>