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