1--TEST-- 2Test parse_ini_file() function 3--FILE-- 4<?php 5/* Prototype: array parse_ini_file(string $filename [,bool $process_sections]); 6 Description: parse_ini_file() loads in the ini file specified in filename, 7 and returns the settings in it in an associative array. 8*/ 9 10$file_path = dirname(__FILE__); 11 12$parse_string = <<<EOD 13; Comment starts with semi-colon(;) 14; Section starts with [<section name>] 15 16; start of ini file 17 18[Constans] 19one = 1 20five = 5 21animal = BIRD 22Language = PHP 23PHP_CONSTANT = 1.2345678 2410 = Ten 25HELLO = HELLO 26 27[date] 28date = 29time = 30 31[paths] 32path = /usr/local/bin 33URL = http://www.php.net 34 35[Decimal] 36Decimal_value1 = 100 37Decimal_value2 = -100 38Decimal_value3 = -2147483647 39Decimal_value4 = 2147483647 40Decimal_value5 = -2147483648 41Decimal_value6 = 2147483648 42 43[Octal] 44Octal_value = 0100 45 46[Hex] 47Hex_value1 = 0x101 48Hex_Value2 = 0x102 49Hex_Value2 = 0x103 50 51[Non-alphanumerics_as_values] 52;Non-alpha numeric chars without quotes 53Non_alpha1 = ; 54Non_alpha2 = + 55Non_alpha3 = * 56Non_alpha4 = % 57Non_alpha5 = <> 58Non_alpha6 = @ 59Non_alpha7 = # 60Non_alpha8 = ^ 61Non_alpha9 = - 62Non_alpha10 = : 63Non_alpha11 = ? 64Non_alpha12 = / 65Non_alpha13 = \ 66;These chars have a special meaning when used in the value, 67; hence parser throws an error 68;Non_alpha14 = & 69;Non_alpha15 = {} 70;Non_alpha16 = | 71;Non_alpha17 = ~ 72;Non_alpha18 = ! 73;Non_alpha19 = $ 74;Non_alpha20 = () 75 76Non_alpha1_quotes = ";" 77Non_alpha2_quotes = "+" 78Non_alpha3_quotes = "*" 79Non_alpha4_quotes = "%" 80Non_alpha5_quotes = "<>" 81Non_alpha6_quotes = "@" 82Non_alpha7_quotes = "#" 83Non_alpha8_quotes = "^" 84Non_alpha9_quotes = "-" 85Non_alpha10_quotes = "=" 86Non_alpha11_quotes = ":" 87Non_alpha12_quotes = "?" 88Non_alpha13_quotes = "/" 89;Non_alpha14_quotes = "\" 90Non_alpha15_quotes = "&" 91Non_alpha16_quotes = "{}" 92Non_alpha17_quotes = "|" 93Non_alpha18_quotes = "~" 94Non_alpha19_quotes = "!" 95;Non_alpha20_quotes = "$" 96Non_alpha21_quotes = "()" 97 98[Non-alpha numerics in strings] 99;expected error, as the non-alphanumeric chars not enclosed in double quotes("") 100Non_alpha_string1 = Hello@world 101;Non_alpha_string2 = Hello!world 102;Non_alpha_string3 = Hello#world 103;Non_alpha_string4 = Hello%world 104;Non_alpha_string5 = Hello&world 105;Non_alpha_string6 = Hello*world 106;Non_alpha_string7 = Hello+world 107;Non_alpha_string8 = Hello-world 108;Non_alpha_string9 = Hello'world 109;Non_alpha_string10 = Hello:world 110;Non_alpha_string11 = Hello;world 111;Non_alpha_string12 = Hello<world 112;Non_alpha_string13 = Hello>world 113;Non_alpha_string14 = Hello>world 114;Non_alpha_string15 = Hello?world 115;Non_alpha_string16 = Hello\world 116;Non_alpha_string17 = Hello^world 117;Non_alpha_string18 = Hello_world 118;Non_alpha_string19 = Hello|world 119;Non_alpha_string20 = Hello~world 120;Non_alpha_string21 = Hello`world 121;Non_alpha_string22 = Hello(world) 122 123[Non-alpha numerics in strings -with quotes] 124Non_alpha_string1_quotes = "Hello@world" 125Non_alpha_string2_quotes = "Hello!world" 126Non_alpha_string3_quotes = "Hello#world" 127Non_alpha_string4_quotes = "Hello&world" 128Non_alpha_string5_quotes = "Hello*world" 129Non_alpha_string6_quotes = "Hello+world" 130Non_alpha_string7_quotes = "Hello-world" 131Non_alpha_string8_quotes = "Hello'world" 132Non_alpha_string9_quotes = "Hello:world" 133Non_alpha_string10_quotes = "Hello;world" 134Non_alpha_string11_quotes = "Hello<world" 135Non_alpha_string12_quotes = "Hello>world" 136Non_alpha_string13_quotes = "Hello>world" 137Non_alpha_string14_quotes = "Hello?world" 138Non_alpha_string15_quotes = "Hello\world" 139Non_alpha_string16_quotes = "Hello^world" 140Non_alpha_string17_quotes = "Hello_world" 141Non_alpha_string18_quotes = "Hello|world" 142Non_alpha_string19_quotes = "Hello~world" 143Non_alpha_string20_quotes = "Hello`world" 144Non_alpha_string21_quotes = "Hello(world)" 145 146[Newlines_in_Values] 147String1 = "Hello, world\nGood Morning" 148String2 = "\nHello, world 149 Good Morning\n" 150String3 = 'Hello, world\tGood Morning' 151String4 = "\n" 152String5 = "\n\n" 153String6 = Hello, world\tGood Morning 154 155[ReservedKeys_as_Values] 156Key1 = YES 157Key2 = Yes 158Key3 = yEs 159Key4 = NO 160Key5 = No 161Key6 = nO 162Key7 = TRUE 163Key8 = True 164Key9 = tRUE 165Key10 = true 166Key11 = FALSE 167Key12 = False 168Key13 = false 169Key14 = fAlSE 170Key15 = NULL 171Key16 = Null 172Key17 = nuLL 173Key18 = null 174 175[ReservedKeys_as_Keys] 176; Expected:error, reserved key words must not be used as keys for ini file 177;YES = 1 178;Yes = 2 179;yEs = 1.2 180;YES = YES 181;NO = "" 182;No = "string" 183;nO = "\0" 184;TRUE = 1.1 185;True = 1 186;tRUE = 5 187;true = TRUE 188;FALSE = FALSE 189;False = "" 190;false = "hello" 191;fAlSE = "" 192;NULL = "" 193;Null = 0 194;nuLL = "\0" 195;null = NULL 196 197; end of ini file 198EOD; 199/* creating parse.ini file */ 200$file_handle = fopen($file_path."/parse.ini", "w"); 201fwrite($file_handle, $parse_string); 202fclose($file_handle); 203 204echo "*** Test parse_ini_file() function: with various keys and values given in parse.ini file ***\n"; 205echo "-- ini file without process_sections optional arg --\n"; 206define('BIRD', 'Humming bird'); 207$ini_array = parse_ini_file($file_path."/parse.ini"); 208print_r($ini_array); 209 210echo "\n-- ini file with process_sections as TRUE --\n"; 211$ini_array = parse_ini_file($file_path."/parse.ini", TRUE); 212print_r($ini_array); 213 214echo "*** Done **\n"; 215?> 216--CLEAN-- 217<?php 218unlink(dirname(__FILE__)."/parse.ini"); 219?> 220--EXPECTF-- 221*** Test parse_ini_file() function: with various keys and values given in parse.ini file *** 222-- ini file without process_sections optional arg -- 223Array 224( 225 [one] => 1 226 [five] => 5 227 [animal] => Humming bird 228 [Language] => PHP 229 [PHP_CONSTANT] => 1.2345678 230 [10] => Ten 231 [HELLO] => HELLO 232 [date] => 233 [time] => 234 [path] => /usr/local/bin 235 [URL] => http://www.php.net 236 [Decimal_value1] => 100 237 [Decimal_value2] => -100 238 [Decimal_value3] => -2147483647 239 [Decimal_value4] => 2147483647 240 [Decimal_value5] => -2147483648 241 [Decimal_value6] => 2147483648 242 [Octal_value] => 0100 243 [Hex_value1] => 0x101 244 [Hex_Value2] => 0x103 245 [Non_alpha1] => 246 [Non_alpha2] => + 247 [Non_alpha3] => * 248 [Non_alpha4] => % 249 [Non_alpha5] => <> 250 [Non_alpha6] => @ 251 [Non_alpha7] => # 252 [Non_alpha8] => ^ 253 [Non_alpha9] => - 254 [Non_alpha10] => : 255 [Non_alpha11] => ? 256 [Non_alpha12] => / 257 [Non_alpha13] => \ 258 [Non_alpha1_quotes] => ; 259 [Non_alpha2_quotes] => + 260 [Non_alpha3_quotes] => * 261 [Non_alpha4_quotes] => % 262 [Non_alpha5_quotes] => <> 263 [Non_alpha6_quotes] => @ 264 [Non_alpha7_quotes] => # 265 [Non_alpha8_quotes] => ^ 266 [Non_alpha9_quotes] => - 267 [Non_alpha10_quotes] => = 268 [Non_alpha11_quotes] => : 269 [Non_alpha12_quotes] => ? 270 [Non_alpha13_quotes] => / 271 [Non_alpha15_quotes] => & 272 [Non_alpha16_quotes] => {} 273 [Non_alpha17_quotes] => | 274 [Non_alpha18_quotes] => ~ 275 [Non_alpha19_quotes] => ! 276 [Non_alpha21_quotes] => () 277 [Non_alpha_string1] => Hello@world 278 [Non_alpha_string1_quotes] => Hello@world 279 [Non_alpha_string2_quotes] => Hello!world 280 [Non_alpha_string3_quotes] => Hello#world 281 [Non_alpha_string4_quotes] => Hello&world 282 [Non_alpha_string5_quotes] => Hello*world 283 [Non_alpha_string6_quotes] => Hello+world 284 [Non_alpha_string7_quotes] => Hello-world 285 [Non_alpha_string8_quotes] => Hello'world 286 [Non_alpha_string9_quotes] => Hello:world 287 [Non_alpha_string10_quotes] => Hello;world 288 [Non_alpha_string11_quotes] => Hello<world 289 [Non_alpha_string12_quotes] => Hello>world 290 [Non_alpha_string13_quotes] => Hello>world 291 [Non_alpha_string14_quotes] => Hello?world 292 [Non_alpha_string15_quotes] => Hello\world 293 [Non_alpha_string16_quotes] => Hello^world 294 [Non_alpha_string17_quotes] => Hello_world 295 [Non_alpha_string18_quotes] => Hello|world 296 [Non_alpha_string19_quotes] => Hello~world 297 [Non_alpha_string20_quotes] => Hello`world 298 [Non_alpha_string21_quotes] => Hello(world) 299 [String1] => Hello, world 300Good Morning 301 [String2] => 302Hello, world 303 Good Morning 304 305 [String3] => Hello, world Good Morning 306 [String4] => 307 308 [String5] => 309 310 311 [String6] => Hello, world Good Morning 312 [Key1] => 1 313 [Key2] => 1 314 [Key3] => 1 315 [Key4] => 316 [Key5] => 317 [Key6] => 318 [Key7] => 1 319 [Key8] => 1 320 [Key9] => 1 321 [Key10] => 1 322 [Key11] => 323 [Key12] => 324 [Key13] => 325 [Key14] => 326 [Key15] => 327 [Key16] => 328 [Key17] => 329 [Key18] => 330) 331 332-- ini file with process_sections as TRUE -- 333Array 334( 335 [Constans] => Array 336 ( 337 [one] => 1 338 [five] => 5 339 [animal] => Humming bird 340 [Language] => PHP 341 [PHP_CONSTANT] => 1.2345678 342 [10] => Ten 343 [HELLO] => HELLO 344 ) 345 346 [date] => Array 347 ( 348 [date] => 349 [time] => 350 ) 351 352 [paths] => Array 353 ( 354 [path] => /usr/local/bin 355 [URL] => http://www.php.net 356 ) 357 358 [Decimal] => Array 359 ( 360 [Decimal_value1] => 100 361 [Decimal_value2] => -100 362 [Decimal_value3] => -2147483647 363 [Decimal_value4] => 2147483647 364 [Decimal_value5] => -2147483648 365 [Decimal_value6] => 2147483648 366 ) 367 368 [Octal] => Array 369 ( 370 [Octal_value] => 0100 371 ) 372 373 [Hex] => Array 374 ( 375 [Hex_value1] => 0x101 376 [Hex_Value2] => 0x103 377 ) 378 379 [Non-alphanumerics_as_values] => Array 380 ( 381 [Non_alpha1] => 382 [Non_alpha2] => + 383 [Non_alpha3] => * 384 [Non_alpha4] => % 385 [Non_alpha5] => <> 386 [Non_alpha6] => @ 387 [Non_alpha7] => # 388 [Non_alpha8] => ^ 389 [Non_alpha9] => - 390 [Non_alpha10] => : 391 [Non_alpha11] => ? 392 [Non_alpha12] => / 393 [Non_alpha13] => \ 394 [Non_alpha1_quotes] => ; 395 [Non_alpha2_quotes] => + 396 [Non_alpha3_quotes] => * 397 [Non_alpha4_quotes] => % 398 [Non_alpha5_quotes] => <> 399 [Non_alpha6_quotes] => @ 400 [Non_alpha7_quotes] => # 401 [Non_alpha8_quotes] => ^ 402 [Non_alpha9_quotes] => - 403 [Non_alpha10_quotes] => = 404 [Non_alpha11_quotes] => : 405 [Non_alpha12_quotes] => ? 406 [Non_alpha13_quotes] => / 407 [Non_alpha15_quotes] => & 408 [Non_alpha16_quotes] => {} 409 [Non_alpha17_quotes] => | 410 [Non_alpha18_quotes] => ~ 411 [Non_alpha19_quotes] => ! 412 [Non_alpha21_quotes] => () 413 ) 414 415 [Non-alpha numerics in strings] => Array 416 ( 417 [Non_alpha_string1] => Hello@world 418 ) 419 420 [Non-alpha numerics in strings -with quotes] => Array 421 ( 422 [Non_alpha_string1_quotes] => Hello@world 423 [Non_alpha_string2_quotes] => Hello!world 424 [Non_alpha_string3_quotes] => Hello#world 425 [Non_alpha_string4_quotes] => Hello&world 426 [Non_alpha_string5_quotes] => Hello*world 427 [Non_alpha_string6_quotes] => Hello+world 428 [Non_alpha_string7_quotes] => Hello-world 429 [Non_alpha_string8_quotes] => Hello'world 430 [Non_alpha_string9_quotes] => Hello:world 431 [Non_alpha_string10_quotes] => Hello;world 432 [Non_alpha_string11_quotes] => Hello<world 433 [Non_alpha_string12_quotes] => Hello>world 434 [Non_alpha_string13_quotes] => Hello>world 435 [Non_alpha_string14_quotes] => Hello?world 436 [Non_alpha_string15_quotes] => Hello\world 437 [Non_alpha_string16_quotes] => Hello^world 438 [Non_alpha_string17_quotes] => Hello_world 439 [Non_alpha_string18_quotes] => Hello|world 440 [Non_alpha_string19_quotes] => Hello~world 441 [Non_alpha_string20_quotes] => Hello`world 442 [Non_alpha_string21_quotes] => Hello(world) 443 ) 444 445 [Newlines_in_Values] => Array 446 ( 447 [String1] => Hello, world 448Good Morning 449 [String2] => 450Hello, world 451 Good Morning 452 453 [String3] => Hello, world Good Morning 454 [String4] => 455 456 [String5] => 457 458 459 [String6] => Hello, world Good Morning 460 ) 461 462 [ReservedKeys_as_Values] => Array 463 ( 464 [Key1] => 1 465 [Key2] => 1 466 [Key3] => 1 467 [Key4] => 468 [Key5] => 469 [Key6] => 470 [Key7] => 1 471 [Key8] => 1 472 [Key9] => 1 473 [Key10] => 1 474 [Key11] => 475 [Key12] => 476 [Key13] => 477 [Key14] => 478 [Key15] => 479 [Key16] => 480 [Key17] => 481 [Key18] => 482 ) 483 484 [ReservedKeys_as_Keys] => Array 485 ( 486 ) 487 488) 489*** Done ** 490