]> granicus.if.org Git - php/blob
60277fa184
[php] /
1 --TEST--
2 Test parse_str() function : basic functionality
3 --FILE--
4 <?php
5
6 /* Prototype  : void parse_str  ( string $str , array &$arr )
7  * Description: Parses the string into variables
8  * Source code: ext/standard/string.c
9 */
10
11 echo "*** Testing parse_str() : basic functionality ***\n";
12
13 echo "\nBasic test WITH undefined var for result arg\n";
14 $s1 = "first=val1&second=val2&third=val3";
15 var_dump(parse_str($s1, $res1));
16 var_dump($res1);
17
18 echo "\nBasic test WITH existing non-array var for result arg\n";
19 $res2 =99;
20 $s1 = "first=val1&second=val2&third=val3";
21 var_dump(parse_str($s1, $res2));
22 var_dump($res2);
23
24 echo "\nBasic test with an existing array as results array\n";
25 $res3_array = array(1,2,3,4);
26 var_dump(parse_str($s1, $res3_array));
27 var_dump($res3_array);
28
29 ?>
30 --EXPECTF--
31 *** Testing parse_str() : basic functionality ***
32
33 Basic test WITH undefined var for result arg
34 NULL
35 array(3) {
36   ["first"]=>
37   string(4) "val1"
38   ["second"]=>
39   string(4) "val2"
40   ["third"]=>
41   string(4) "val3"
42 }
43
44 Basic test WITH existing non-array var for result arg
45 NULL
46 array(3) {
47   ["first"]=>
48   string(4) "val1"
49   ["second"]=>
50   string(4) "val2"
51   ["third"]=>
52   string(4) "val3"
53 }
54
55 Basic test with an existing array as results array
56 NULL
57 array(3) {
58   ["first"]=>
59   string(4) "val1"
60   ["second"]=>
61   string(4) "val2"
62   ["third"]=>
63   string(4) "val3"
64 }