1--TEST-- 2Test parse_str() function : basic functionality 3--INI-- 4max_input_vars=1000 5filter.default=unsafe_raw 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 13echo "*** Testing parse_str() : basic functionality ***\n"; 14 15echo "\nTest string with array values\n"; 16$s1 = "first=abc&a[]=123&a[]=false&b[]=str&c[]=3.5&a[]=last"; 17var_dump(parse_str($s1)); 18var_dump($first, $a, $b, $c); 19 20echo "\nTest string with array values and results array\n"; 21$s1 = "first=abc&a[]=123&a[]=false&b[]=str&c[]=3.5&a[]=last"; 22var_dump(parse_str($s1, $res3_array)); 23var_dump($res3_array); 24 25echo "\nTest string containing numerical array keys\n"; 26$str = "arr[1]=sid&arr[4]=bill"; 27var_dump(parse_str($str, $res)); 28var_dump($res); 29 30echo "\nTest string containing associative keys\n"; 31$str = "arr[first]=sid&arr[forth]=bill"; 32var_dump(parse_str($str, $res)); 33var_dump($res); 34 35echo "\nTest string with array values with same name as existing variable\n"; 36$a = 9999; 37$s1 = "a[]=123&a[]=false&a[]=last"; 38var_dump(parse_str($s1)); 39var_dump($a); 40 41echo "\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"; 44parse_str($s1); 45var_dump($a); 46 47echo "\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"; 49parse_str($s1); 50var_dump($a, $b); 51 52echo "\nTest string with single quotes characters\n"; 53$s1 = "firstname=Bill&surname=O%27Reilly"; 54var_dump(parse_str($s1)); 55var_dump($firstname, $surname); 56 57echo "\nTest string with backslash characters\n"; 58$s1 = "sum=10%5c2%3d5"; 59var_dump(parse_str($s1)); 60var_dump($sum); 61 62echo "\nTest string with double quotes data\n"; 63$s1 = "str=A+string+with+%22quoted%22+strings"; 64var_dump(parse_str($s1)); 65var_dump($str); 66 67echo "\nTest string with nulls\n"; 68$s1 = "str=A%20string%20with%20containing%20%00%00%00%20nulls"; 69var_dump(parse_str($s1)); 70var_dump($str); 71 72echo "\nTest string with 2-dim array with numeric keys\n"; 73$str = "arr[3][4]=sid&arr[3][6]=fred"; 74var_dump(parse_str($str, $res)); 75var_dump($res); 76 77echo "\nTest string with 2-dim array with null keys\n"; 78$str = "arr[][]=sid&arr[][]=fred"; 79var_dump(parse_str($str, $res)); 80var_dump($res); 81 82echo "\nTest string with 2-dim array with non-numeric keys\n"; 83$str = "arr[one][four]=sid&arr[three][six]=fred"; 84var_dump(parse_str($str, $res)); 85var_dump($res); 86 87echo "\nTest string with 3-dim array with numeric keys\n"; 88$str = "arr[1][2][3]=sid&arr[1][2][6]=fred"; 89var_dump(parse_str($str, $res)); 90var_dump($res); 91 92?> 93===DONE=== 94--EXPECTF-- 95*** Testing parse_str() : basic functionality *** 96 97Test string with array values 98NULL 99string(3) "abc" 100array(3) { 101 [0]=> 102 string(3) "123" 103 [1]=> 104 string(5) "false" 105 [2]=> 106 string(4) "last" 107} 108array(1) { 109 [0]=> 110 string(3) "str" 111} 112array(1) { 113 [0]=> 114 string(3) "3.5" 115} 116 117Test string with array values and results array 118NULL 119array(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 143Test string containing numerical array keys 144NULL 145array(1) { 146 ["arr"]=> 147 array(2) { 148 [1]=> 149 string(3) "sid" 150 [4]=> 151 string(4) "bill" 152 } 153} 154 155Test string containing associative keys 156NULL 157array(1) { 158 ["arr"]=> 159 array(2) { 160 ["first"]=> 161 string(3) "sid" 162 ["forth"]=> 163 string(4) "bill" 164 } 165} 166 167Test string with array values with same name as existing variable 168NULL 169array(3) { 170 [0]=> 171 string(3) "123" 172 [1]=> 173 string(5) "false" 174 [2]=> 175 string(4) "last" 176} 177 178Test string with non-array value with same name as existing array variable 179string(3) "999" 180 181Test string with encoded data 182string(17) "<== foo bar ==>" 183string(17) "###Hello World###" 184 185Test string with single quotes characters 186NULL 187string(4) "Bill" 188string(8) "O'Reilly" 189 190Test string with backslash characters 191NULL 192string(6) "10\2=5" 193 194Test string with double quotes data 195NULL 196string(30) "A string with "quoted" strings" 197 198Test string with nulls 199NULL 200string(34) "A string with containing nulls" 201 202Test string with 2-dim array with numeric keys 203NULL 204array(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 217Test string with 2-dim array with null keys 218NULL 219array(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 235Test string with 2-dim array with non-numeric keys 236NULL 237array(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 253Test string with 3-dim array with numeric keys 254NULL 255array(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=== 271