1--TEST-- 2Test parse_str() function : basic functionality 3--INI-- 4max_input_vars=100 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, $res); 50var_dump($res); 51 52echo "\nTest string with single quotes characters\n"; 53$s1 = "firstname=Bill&surname=O%27Reilly"; 54var_dump(parse_str($s1, $res)); 55var_dump($res); 56 57echo "\nTest string with backslash characters\n"; 58$s1 = "sum=10%5c2%3d5"; 59var_dump(parse_str($s1, $res)); 60var_dump($res); 61 62echo "\nTest string with double quotes data\n"; 63$s1 = "str=A+string+with+%22quoted%22+strings"; 64var_dump(parse_str($s1, $res)); 65var_dump($res); 66 67echo "\nTest string with nulls\n"; 68$s1 = "str=A%20string%20with%20containing%20%00%00%00%20nulls"; 69var_dump(parse_str($s1, $res)); 70var_dump($res); 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 98 99Deprecated: parse_str(): Calling parse_str() without the result argument is deprecated in %s on line %d 100NULL 101string(3) "abc" 102array(3) { 103 [0]=> 104 string(3) "123" 105 [1]=> 106 string(5) "false" 107 [2]=> 108 string(4) "last" 109} 110array(1) { 111 [0]=> 112 string(3) "str" 113} 114array(1) { 115 [0]=> 116 string(3) "3.5" 117} 118 119Test string with array values and results array 120NULL 121array(4) { 122 ["first"]=> 123 string(3) "abc" 124 ["a"]=> 125 array(3) { 126 [0]=> 127 string(3) "123" 128 [1]=> 129 string(5) "false" 130 [2]=> 131 string(4) "last" 132 } 133 ["b"]=> 134 array(1) { 135 [0]=> 136 string(3) "str" 137 } 138 ["c"]=> 139 array(1) { 140 [0]=> 141 string(3) "3.5" 142 } 143} 144 145Test string containing numerical array keys 146NULL 147array(1) { 148 ["arr"]=> 149 array(2) { 150 [1]=> 151 string(3) "sid" 152 [4]=> 153 string(4) "bill" 154 } 155} 156 157Test string containing associative keys 158NULL 159array(1) { 160 ["arr"]=> 161 array(2) { 162 ["first"]=> 163 string(3) "sid" 164 ["forth"]=> 165 string(4) "bill" 166 } 167} 168 169Test string with array values with same name as existing variable 170 171Deprecated: parse_str(): Calling parse_str() without the result argument is deprecated in %s on line %d 172NULL 173array(3) { 174 [0]=> 175 string(3) "123" 176 [1]=> 177 string(5) "false" 178 [2]=> 179 string(4) "last" 180} 181 182Test string with non-array value with same name as existing array variable 183 184Deprecated: parse_str(): Calling parse_str() without the result argument is deprecated in %s on line %d 185string(3) "999" 186 187Test string with encoded data 188array(2) { 189 ["a"]=> 190 string(17) "<== foo bar ==>" 191 ["b"]=> 192 string(17) "###Hello World###" 193} 194 195Test string with single quotes characters 196NULL 197array(2) { 198 ["firstname"]=> 199 string(4) "Bill" 200 ["surname"]=> 201 string(8) "O'Reilly" 202} 203 204Test string with backslash characters 205NULL 206array(1) { 207 ["sum"]=> 208 string(6) "10\2=5" 209} 210 211Test string with double quotes data 212NULL 213array(1) { 214 ["str"]=> 215 string(30) "A string with "quoted" strings" 216} 217 218Test string with nulls 219NULL 220array(1) { 221 ["str"]=> 222 string(34) "A string with containing nulls" 223} 224 225Test string with 2-dim array with numeric keys 226NULL 227array(1) { 228 ["arr"]=> 229 array(1) { 230 [3]=> 231 array(2) { 232 [4]=> 233 string(3) "sid" 234 [6]=> 235 string(4) "fred" 236 } 237 } 238} 239 240Test string with 2-dim array with null keys 241NULL 242array(1) { 243 ["arr"]=> 244 array(2) { 245 [0]=> 246 array(1) { 247 [0]=> 248 string(3) "sid" 249 } 250 [1]=> 251 array(1) { 252 [0]=> 253 string(4) "fred" 254 } 255 } 256} 257 258Test string with 2-dim array with non-numeric keys 259NULL 260array(1) { 261 ["arr"]=> 262 array(2) { 263 ["one"]=> 264 array(1) { 265 ["four"]=> 266 string(3) "sid" 267 } 268 ["three"]=> 269 array(1) { 270 ["six"]=> 271 string(4) "fred" 272 } 273 } 274} 275 276Test string with 3-dim array with numeric keys 277NULL 278array(1) { 279 ["arr"]=> 280 array(1) { 281 [1]=> 282 array(1) { 283 [2]=> 284 array(2) { 285 [3]=> 286 string(3) "sid" 287 [6]=> 288 string(4) "fred" 289 } 290 } 291 } 292} 293===DONE=== 294