<HTML ><HEAD ><TITLE >parse_str</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="String functions" HREF="ref.strings.html"><LINK REL="PREVIOUS" TITLE="ord" HREF="function.ord.html"><LINK REL="NEXT" TITLE="print" HREF="function.print.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></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" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.ord.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.print.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.parse-str" ></A >parse_str</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN90324" ></A ><P > (PHP 3, PHP 4 )</P >parse_str -- Parses the string into variables</DIV ><DIV CLASS="refsect1" ><A NAME="AEN90327" ></A ><H2 >Description</H2 >void <B CLASS="methodname" >parse_str</B > ( string str [, array arr])<BR ></BR ><P > Parses <TT CLASS="parameter" ><I >str</I ></TT > as if it were the query string passed via an URL and sets variables in the current scope. If the second parameter <TT CLASS="parameter" ><I >arr</I ></TT > is present, variables are stored in this variable as an array elements instead. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > Support for the optional second parameter was added in PHP 4.0.3. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > To get the current <SPAN CLASS="emphasis" ><I CLASS="emphasis" >QUERY_STRING</I ></SPAN >, you may use the variable <A HREF="reserved.variables.html#reserved.variables.server" >$_SERVER['QUERY_STRING']</A >. Also, you may want to read the section on <A HREF="language.variables.external.html" >variables from outside of PHP</A >. </P ></BLOCKQUOTE ></DIV ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN90349" ></A ><P ><B >Example 1. Using <B CLASS="function" >parse_str()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $str = "first=value&arr[]=foo+bar&arr[]=baz"; parse_str($str); echo $first; // value echo $arr[0]; // foo bar echo $arr[1]; // baz parse_str($str, $output); echo $output['first']; // value echo $output['arr'][0]; // foo bar echo $output['arr'][1]; // baz ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > See also <A HREF="function.parse-url.html" ><B CLASS="function" >parse_url()</B ></A >, <A HREF="function.pathinfo.html" ><B CLASS="function" >pathinfo()</B ></A >, <A HREF="function.set-magic-quotes-runtime.html" ><B CLASS="function" >set_magic_quotes_runtime()</B ></A >, and <A HREF="function.urldecode.html" ><B CLASS="function" >urldecode()</B ></A >. </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.ord.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.print.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >ord</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.strings.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >print</TD ></TR ></TABLE ></DIV ></BODY ></HTML >