<!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>Parses the string into variables</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.ord.html">ord</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.print.html">print</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.parse-str" class="refentry"> <div class="refnamediv"> <h1 class="refname">parse_str</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">parse_str</span> — <span class="dc-title">Parses the string into variables</span></p> </div> <div class="refsect1 description" id="refsect1-function.parse-str-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>parse_str</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span> [, <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$arr</code></span> ] )</div> <p class="para rdfs-comment"> Parses <em><code class="parameter">str</code></em> as if it were the query string passed via a URL and sets variables in the current scope. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> To get the current <em>QUERY_STRING</em>, you may use the variable <var class="varname"><var class="varname"><a href="reserved.variables.server.html" class="classname">$_SERVER['QUERY_STRING']</a></var></var>. Also, you may want to read the section on <a href="language.variables.external.html" class="link">variables from external sources</a>. </p> </p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> The <a href="info.configuration.html#ini.magic-quotes-gpc" class="link">magic_quotes_gpc</a> setting affects the output of this function, as <span class="function"><strong>parse_str()</strong></span> uses the same mechanism that PHP uses to populate the <var class="varname"><var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET</a></var></var>, <var class="varname"><var class="varname"><a href="reserved.variables.post.html" class="classname">$_POST</a></var></var>, etc. variables. </p> </p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-function.parse-str-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 input string. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">arr</code></em></span> <dd> <p class="para"> If the second parameter <em><code class="parameter">arr</code></em> is present, variables are stored in this variable as array elements instead. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.parse-str-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> No value is returned. </p> </div> <div class="refsect1 changelog" id="refsect1-function.parse-str-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>4.0.3</td> <td> The <em><code class="parameter">arr</code></em> parameter was added </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.parse-str-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4855"> <p><strong>Example #1 Using <span class="function"><strong>parse_str()</strong></span></strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$str </span><span style="color: #007700">= </span><span style="color: #DD0000">"first=value&arr[]=foo+bar&arr[]=baz"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">parse_str</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$first</span><span style="color: #007700">; </span><span style="color: #FF8000">// value<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$arr</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]; </span><span style="color: #FF8000">// foo bar<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$arr</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]; </span><span style="color: #FF8000">// baz<br /><br /></span><span style="color: #0000BB">parse_str</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">, </span><span style="color: #0000BB">$output</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$output</span><span style="color: #007700">[</span><span style="color: #DD0000">'first'</span><span style="color: #007700">]; </span><span style="color: #FF8000">// value<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$output</span><span style="color: #007700">[</span><span style="color: #DD0000">'arr'</span><span style="color: #007700">][</span><span style="color: #0000BB">0</span><span style="color: #007700">]; </span><span style="color: #FF8000">// foo bar<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$output</span><span style="color: #007700">[</span><span style="color: #DD0000">'arr'</span><span style="color: #007700">][</span><span style="color: #0000BB">1</span><span style="color: #007700">]; </span><span style="color: #FF8000">// baz<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.parse-str-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.parse-url.html" class="function" rel="rdfs-seeAlso">parse_url()</a> - Parse a URL and return its components</span></li> <li class="member"> <span class="function"><a href="function.pathinfo.html" class="function" rel="rdfs-seeAlso">pathinfo()</a> - Returns information about a file path</span></li> <li class="member"> <span class="function"><a href="function.http-build-query.html" class="function" rel="rdfs-seeAlso">http_build_query()</a> - Generate URL-encoded query string</span></li> <li class="member"> <span class="function"><a href="function.get-magic-quotes-gpc.html" class="function" rel="rdfs-seeAlso">get_magic_quotes_gpc()</a> - Gets the current configuration setting of magic_quotes_gpc</span></li> <li class="member"> <span class="function"><a href="function.urldecode.html" class="function" rel="rdfs-seeAlso">urldecode()</a> - Decodes URL-encoded string</span></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.ord.html">ord</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.print.html">print</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>