1--TEST-- 2Test parse_str() function : basic functionality 3--INI-- 4magic_quotes_gpc = on 5max_input_vars=1000 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-- 95Deprecated: Directive 'magic_quotes_gpc' is deprecated in PHP 5.3 and greater in Unknown on line 0 96*** Testing parse_str() : basic functionality *** 97 98Test string with array values 99NULL 100string(3) "abc" 101array(3) { 102 [0]=> 103 string(3) "123" 104 [1]=> 105 string(5) "false" 106 [2]=> 107 string(4) "last" 108} 109array(1) { 110 [0]=> 111 string(3) "str" 112} 113array(1) { 114 [0]=> 115 string(3) "3.5" 116} 117 118Test string with array values and results array 119NULL 120array(4) { 121 ["first"]=> 122 string(3) "abc" 123 ["a"]=> 124 array(3) { 125 [0]=> 126 string(3) "123" 127 [1]=> 128 string(5) "false" 129 [2]=> 130 string(4) "last" 131 } 132 ["b"]=> 133 array(1) { 134 [0]=> 135 string(3) "str" 136 } 137 ["c"]=> 138 array(1) { 139 [0]=> 140 string(3) "3.5" 141 } 142} 143 144Test string containing numerical array keys 145NULL 146array(1) { 147 ["arr"]=> 148 array(2) { 149 [1]=> 150 string(3) "sid" 151 [4]=> 152 string(4) "bill" 153 } 154} 155 156Test string containing associative keys 157NULL 158array(1) { 159 ["arr"]=> 160 array(2) { 161 ["first"]=> 162 string(3) "sid" 163 ["forth"]=> 164 string(4) "bill" 165 } 166} 167 168Test string with array values with same name as existing variable 169NULL 170array(3) { 171 [0]=> 172 string(3) "123" 173 [1]=> 174 string(5) "false" 175 [2]=> 176 string(4) "last" 177} 178 179Test string with non-array value with same name as existing array variable 180string(3) "999" 181 182Test string with encoded data 183string(17) "<== foo bar ==>" 184string(17) "###Hello World###" 185 186Test string with single quotes characters 187NULL 188string(4) "Bill" 189string(9) "O\'Reilly" 190 191Test string with backslash characters 192NULL 193string(7) "10\\2=5" 194 195Test string with double quotes data 196NULL 197string(32) "A string with \"quoted\" strings" 198 199Test string with nulls 200NULL 201string(37) "A string with containing \0\0\0 nulls" 202 203Test string with 2-dim array with numeric keys 204NULL 205array(1) { 206 ["arr"]=> 207 array(1) { 208 [3]=> 209 array(2) { 210 [4]=> 211 string(3) "sid" 212 [6]=> 213 string(4) "fred" 214 } 215 } 216} 217 218Test string with 2-dim array with null keys 219NULL 220array(1) { 221 ["arr"]=> 222 array(2) { 223 [0]=> 224 array(1) { 225 [0]=> 226 string(3) "sid" 227 } 228 [1]=> 229 array(1) { 230 [0]=> 231 string(4) "fred" 232 } 233 } 234} 235 236Test string with 2-dim array with non-numeric keys 237NULL 238array(1) { 239 ["arr"]=> 240 array(2) { 241 ["one"]=> 242 array(1) { 243 ["four"]=> 244 string(3) "sid" 245 } 246 ["three"]=> 247 array(1) { 248 ["six"]=> 249 string(4) "fred" 250 } 251 } 252} 253 254Test string with 3-dim array with numeric keys 255NULL 256array(1) { 257 ["arr"]=> 258 array(1) { 259 [1]=> 260 array(1) { 261 [2]=> 262 array(2) { 263 [3]=> 264 string(3) "sid" 265 [6]=> 266 string(4) "fred" 267 } 268 } 269 } 270} 271===DONE=== 272