3
3
<refentry xml : id =" function.parse-str" xmlns =" http://docbook.org/ns/docbook" >
4
4
<refnamediv >
5
5
<refname >parse_str</refname >
6
- <refpurpose >Parses the string into variables </refpurpose >
6
+ <refpurpose >Parse a string as a URL query string </refpurpose >
7
7
</refnamediv >
8
8
9
9
<refsect1 role =" description" >
15
15
</methodsynopsis >
16
16
<para >
17
17
Parses <parameter >string</parameter > as if it were the query string
18
- passed via a URL and sets variables in the current scope (or in the array
19
- if <parameter >result</parameter > is provided).
18
+ passed via a URL and sets keys in the provided <parameter >result</parameter >
19
+ array. If no <parameter >result</parameter > is passed, values are instead
20
+ set as variables in the current scope.
20
21
</para >
21
22
</refsect1 >
22
23
36
37
<term ><parameter >result</parameter ></term >
37
38
<listitem >
38
39
<para >
39
- If the second parameter <parameter >result</parameter > is present,
40
- variables are stored in this variable as array elements instead.
40
+ A variable passed by reference, which will be set to an array
41
+ containing the key-value pairs extracted from <parameter >string</parameter >.
42
+ If the <parameter >result</parameter > parameter is not passed,
43
+ a separate variable is set in the local scope for each key.
41
44
</para >
42
45
43
46
<warning >
@@ -112,9 +115,10 @@ echo $output['arr'][1], PHP_EOL; // baz
112
115
</example >
113
116
</para >
114
117
<para >
115
- Because variables in PHP can't have dots and spaces in their names,
116
- those are converted to underscores. Same applies to naming of
117
- respective key names in case of using this function with
118
+ Any spaces and dots in parameter names are converted to underscores
119
+ when creating array keys or local variables.
120
+ This is because variable names in PHP are not allowed to contain spaces
121
+ or dots, but applies even when using this function with the recommended
118
122
<parameter >result</parameter > parameter.
119
123
<example >
120
124
<title ><function >parse_str</function > name mangling</title >
@@ -135,7 +139,7 @@ echo $output['My_Value']; // Something
135
139
136
140
<note >
137
141
<para >
138
- <function >parse_str() </function > is affected by the <link linkend =" ini.max-input-vars" >max_input_vars</link >
142
+ <function >parse_str</function > is affected by the <link linkend =" ini.max-input-vars" >max_input_vars</link >
139
143
directive. Exceeding this limit triggers an <constant >E_WARNING</constant >,
140
144
and any variables beyond the limit are not added to the result array.
141
145
The default is 1000; adjust <link linkend =" ini.max-input-vars" >max_input_vars</link > as needed.
@@ -144,13 +148,14 @@ echo $output['My_Value']; // Something
144
148
145
149
<note >
146
150
<para >
147
- All variables created (or values returned into array if second parameter is set)
148
- are already <function >urldecode</function >d.
151
+ All values populated in the <parameter >result</parameter > array
152
+ (or variables created if second parameter is not set)
153
+ are already URL-decoded using the same rules as <function >urldecode</function >.
149
154
</para >
150
155
</note >
151
156
<note >
152
157
<para >
153
- To get the current < literal >QUERY_STRING</ literal > , you may use the variable
158
+ To get the query string of the current request , you may use the variable
154
159
<varname >$_SERVER['QUERY_STRING']</varname >.
155
160
Also, you may want to read the section on
156
161
<link linkend =" language.variables.external" >variables from external
0 commit comments