File: parse_str_basic3.phpt

package info (click to toggle)
php5 5.3.3-7%2Bsqueeze19
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 122,836 kB
  • ctags: 55,742
  • sloc: ansic: 633,963; php: 19,620; sh: 11,344; xml: 5,816; cpp: 2,400; yacc: 1,745; exp: 1,514; makefile: 1,019; pascal: 623; awk: 537; sql: 22
file content (270 lines) | stat: -rw-r--r-- 5,220 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
--TEST--
Test parse_str() function : basic functionality
--INI--
magic_quotes_gpc = on
--FILE--
<?php
/* Prototype  : void parse_str  ( string $str  [, array &$arr  ] )
 * Description: Parses the string into variables
 * Source code: ext/standard/string.c
*/

echo "*** Testing parse_str() : basic functionality ***\n";

echo "\nTest string with array values\n";
$s1 = "first=abc&a[]=123&a[]=false&b[]=str&c[]=3.5&a[]=last";
var_dump(parse_str($s1));
var_dump($first, $a, $b, $c); 

echo "\nTest string with array values and results array\n";
$s1 = "first=abc&a[]=123&a[]=false&b[]=str&c[]=3.5&a[]=last";
var_dump(parse_str($s1, $res3_array));
var_dump($res3_array); 

echo "\nTest string containing numerical array keys\n";
$str = "arr[1]=sid&arr[4]=bill";
var_dump(parse_str($str, $res));
var_dump($res);

echo "\nTest string containing associative keys\n";
$str = "arr[first]=sid&arr[forth]=bill";
var_dump(parse_str($str, $res));
var_dump($res);

echo "\nTest string with array values with same name as existing variable\n";
$a = 9999;
$s1 = "a[]=123&a[]=false&a[]=last";
var_dump(parse_str($s1));
var_dump($a);

echo "\nTest string with non-array value with same name as existing array variable\n";
$a = array(10,11,12,13);
$s1 = "a=999";
parse_str($s1);
var_dump($a);

echo "\nTest string with encoded data\n";
$s1 = "a=%3c%3d%3d%20%20foo+bar++%3d%3d%3e&b=%23%23%23Hello+World%23%23%23";
parse_str($s1);
var_dump($a, $b);

echo "\nTest string with single quotes characters\n";
$s1 = "firstname=Bill&surname=O%27Reilly";
var_dump(parse_str($s1));
var_dump($firstname, $surname);

echo "\nTest string with backslash characters\n";
$s1 = "sum=10%5c2%3d5";
var_dump(parse_str($s1));
var_dump($sum);

echo "\nTest string with double quotes data\n";
$s1 = "str=A+string+with+%22quoted%22+strings";
var_dump(parse_str($s1));
var_dump($str);

echo "\nTest string with nulls\n";
$s1 = "str=A%20string%20with%20containing%20%00%00%00%20nulls";
var_dump(parse_str($s1));
var_dump($str);

echo "\nTest string with 2-dim array with numeric keys\n";
$str = "arr[3][4]=sid&arr[3][6]=fred";
var_dump(parse_str($str, $res));
var_dump($res);

echo "\nTest string with 2-dim array with null keys\n";
$str = "arr[][]=sid&arr[][]=fred";
var_dump(parse_str($str, $res));
var_dump($res);

echo "\nTest string with 2-dim array with non-numeric keys\n";
$str = "arr[one][four]=sid&arr[three][six]=fred";
var_dump(parse_str($str, $res));
var_dump($res);

echo "\nTest string with 3-dim array with numeric keys\n";
$str = "arr[1][2][3]=sid&arr[1][2][6]=fred";
var_dump(parse_str($str, $res));
var_dump($res);

?>
===DONE===
--EXPECTF--
Warning: Directive 'magic_quotes_gpc' is deprecated in PHP 5.3 and greater in Unknown on line 0
*** Testing parse_str() : basic functionality ***

Test string with array values
NULL
string(3) "abc"
array(3) {
  [0]=>
  string(3) "123"
  [1]=>
  string(5) "false"
  [2]=>
  string(4) "last"
}
array(1) {
  [0]=>
  string(3) "str"
}
array(1) {
  [0]=>
  string(3) "3.5"
}

Test string with array values and results array
NULL
array(4) {
  ["first"]=>
  string(3) "abc"
  ["a"]=>
  array(3) {
    [0]=>
    string(3) "123"
    [1]=>
    string(5) "false"
    [2]=>
    string(4) "last"
  }
  ["b"]=>
  array(1) {
    [0]=>
    string(3) "str"
  }
  ["c"]=>
  array(1) {
    [0]=>
    string(3) "3.5"
  }
}

Test string containing numerical array keys
NULL
array(1) {
  ["arr"]=>
  array(2) {
    [1]=>
    string(3) "sid"
    [4]=>
    string(4) "bill"
  }
}

Test string containing associative keys
NULL
array(1) {
  ["arr"]=>
  array(2) {
    ["first"]=>
    string(3) "sid"
    ["forth"]=>
    string(4) "bill"
  }
}

Test string with array values with same name as existing variable
NULL
array(3) {
  [0]=>
  string(3) "123"
  [1]=>
  string(5) "false"
  [2]=>
  string(4) "last"
}

Test string with non-array value with same name as existing array variable
string(3) "999"

Test string with encoded data
string(17) "<==  foo bar  ==>"
string(17) "###Hello World###"

Test string with single quotes characters
NULL
string(4) "Bill"
string(9) "O\'Reilly"

Test string with backslash characters
NULL
string(7) "10\\2=5"

Test string with double quotes data
NULL
string(32) "A string with \"quoted\" strings"

Test string with nulls
NULL
string(37) "A string with containing \0\0\0 nulls"

Test string with 2-dim array with numeric keys
NULL
array(1) {
  ["arr"]=>
  array(1) {
    [3]=>
    array(2) {
      [4]=>
      string(3) "sid"
      [6]=>
      string(4) "fred"
    }
  }
}

Test string with 2-dim array with null keys
NULL
array(1) {
  ["arr"]=>
  array(2) {
    [0]=>
    array(1) {
      [0]=>
      string(3) "sid"
    }
    [1]=>
    array(1) {
      [0]=>
      string(4) "fred"
    }
  }
}

Test string with 2-dim array with non-numeric keys
NULL
array(1) {
  ["arr"]=>
  array(2) {
    ["one"]=>
    array(1) {
      ["four"]=>
      string(3) "sid"
    }
    ["three"]=>
    array(1) {
      ["six"]=>
      string(4) "fred"
    }
  }
}

Test string with 3-dim array with numeric keys
NULL
array(1) {
  ["arr"]=>
  array(1) {
    [1]=>
    array(1) {
      [2]=>
      array(2) {
        [3]=>
        string(3) "sid"
        [6]=>
        string(4) "fred"
      }
    }
  }
}
===DONE===