1--TEST--
2Test parse_str() function : basic functionality
3--INI--
4max_input_vars=100
5filter.default=unsafe_raw
6--FILE--
7<?php
8echo "*** Testing parse_str() : basic functionality ***\n";
9
10echo "\nTest string with array values and results array\n";
11$s1 = "first=abc&a[]=123&a[]=false&b[]=str&c[]=3.5&a[]=last";
12var_dump(parse_str($s1, $res3_array));
13var_dump($res3_array);
14
15echo "\nTest string containing numerical array keys\n";
16$str = "arr[1]=sid&arr[4]=bill";
17var_dump(parse_str($str, $res));
18var_dump($res);
19
20echo "\nTest string containing associative keys\n";
21$str = "arr[first]=sid&arr[forth]=bill";
22var_dump(parse_str($str, $res));
23var_dump($res);
24
25echo "\nTest string with encoded data\n";
26$s1 = "a=%3c%3d%3d%20%20foo+bar++%3d%3d%3e&b=%23%23%23Hello+World%23%23%23";
27parse_str($s1, $res);
28var_dump($res);
29
30echo "\nTest string with single quotes characters\n";
31$s1 = "firstname=Bill&surname=O%27Reilly";
32var_dump(parse_str($s1, $res));
33var_dump($res);
34
35echo "\nTest string with backslash characters\n";
36$s1 = "sum=10%5c2%3d5";
37var_dump(parse_str($s1, $res));
38var_dump($res);
39
40echo "\nTest string with double quotes data\n";
41$s1 = "str=A+string+with+%22quoted%22+strings";
42var_dump(parse_str($s1, $res));
43var_dump($res);
44
45echo "\nTest string with nulls\n";
46$s1 = "str=A%20string%20with%20containing%20%00%00%00%20nulls";
47var_dump(parse_str($s1, $res));
48var_dump($res);
49
50echo "\nTest string with 2-dim array with numeric keys\n";
51$str = "arr[3][4]=sid&arr[3][6]=fred";
52var_dump(parse_str($str, $res));
53var_dump($res);
54
55echo "\nTest string with 2-dim array with null keys\n";
56$str = "arr[][]=sid&arr[][]=fred";
57var_dump(parse_str($str, $res));
58var_dump($res);
59
60echo "\nTest string with 2-dim array with non-numeric keys\n";
61$str = "arr[one][four]=sid&arr[three][six]=fred";
62var_dump(parse_str($str, $res));
63var_dump($res);
64
65echo "\nTest string with 3-dim array with numeric keys\n";
66$str = "arr[1][2][3]=sid&arr[1][2][6]=fred";
67var_dump(parse_str($str, $res));
68var_dump($res);
69
70?>
71--EXPECTF--
72*** Testing parse_str() : basic functionality ***
73
74Test string with array values and results array
75NULL
76array(4) {
77  ["first"]=>
78  string(3) "abc"
79  ["a"]=>
80  array(3) {
81    [0]=>
82    string(3) "123"
83    [1]=>
84    string(5) "false"
85    [2]=>
86    string(4) "last"
87  }
88  ["b"]=>
89  array(1) {
90    [0]=>
91    string(3) "str"
92  }
93  ["c"]=>
94  array(1) {
95    [0]=>
96    string(3) "3.5"
97  }
98}
99
100Test string containing numerical array keys
101NULL
102array(1) {
103  ["arr"]=>
104  array(2) {
105    [1]=>
106    string(3) "sid"
107    [4]=>
108    string(4) "bill"
109  }
110}
111
112Test string containing associative keys
113NULL
114array(1) {
115  ["arr"]=>
116  array(2) {
117    ["first"]=>
118    string(3) "sid"
119    ["forth"]=>
120    string(4) "bill"
121  }
122}
123
124Test string with encoded data
125array(2) {
126  ["a"]=>
127  string(17) "<==  foo bar  ==>"
128  ["b"]=>
129  string(17) "###Hello World###"
130}
131
132Test string with single quotes characters
133NULL
134array(2) {
135  ["firstname"]=>
136  string(4) "Bill"
137  ["surname"]=>
138  string(8) "O'Reilly"
139}
140
141Test string with backslash characters
142NULL
143array(1) {
144  ["sum"]=>
145  string(6) "10\2=5"
146}
147
148Test string with double quotes data
149NULL
150array(1) {
151  ["str"]=>
152  string(30) "A string with "quoted" strings"
153}
154
155Test string with nulls
156NULL
157array(1) {
158  ["str"]=>
159  string(34) "A string with containing %0%0%0 nulls"
160}
161
162Test string with 2-dim array with numeric keys
163NULL
164array(1) {
165  ["arr"]=>
166  array(1) {
167    [3]=>
168    array(2) {
169      [4]=>
170      string(3) "sid"
171      [6]=>
172      string(4) "fred"
173    }
174  }
175}
176
177Test string with 2-dim array with null keys
178NULL
179array(1) {
180  ["arr"]=>
181  array(2) {
182    [0]=>
183    array(1) {
184      [0]=>
185      string(3) "sid"
186    }
187    [1]=>
188    array(1) {
189      [0]=>
190      string(4) "fred"
191    }
192  }
193}
194
195Test string with 2-dim array with non-numeric keys
196NULL
197array(1) {
198  ["arr"]=>
199  array(2) {
200    ["one"]=>
201    array(1) {
202      ["four"]=>
203      string(3) "sid"
204    }
205    ["three"]=>
206    array(1) {
207      ["six"]=>
208      string(4) "fred"
209    }
210  }
211}
212
213Test string with 3-dim array with numeric keys
214NULL
215array(1) {
216  ["arr"]=>
217  array(1) {
218    [1]=>
219    array(1) {
220      [2]=>
221      array(2) {
222        [3]=>
223        string(3) "sid"
224        [6]=>
225        string(4) "fred"
226      }
227    }
228  }
229}
230