Annotation of embedaddon/php/ext/standard/tests/file/parse_ini_file.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test 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]
                     19: one = 1
                     20: five = 5
                     21: animal = BIRD
                     22: Language = PHP
                     23: PHP_CONSTANT = 1.2345678
                     24: 10 = Ten
                     25: HELLO = HELLO
                     26: 
                     27: [date]
                     28: date = 
                     29: time =
                     30: 
                     31: [paths]
                     32: path = /usr/local/bin
                     33: URL = http://www.php.net
                     34: 
                     35: [Decimal]
                     36: Decimal_value1 = 100
                     37: Decimal_value2 = -100
                     38: Decimal_value3 = -2147483647
                     39: Decimal_value4 = 2147483647
                     40: Decimal_value5 = -2147483648
                     41: Decimal_value6 = 2147483648
                     42: 
                     43: [Octal]
                     44: Octal_value = 0100
                     45: 
                     46: [Hex]
                     47: Hex_value1 = 0x101
                     48: Hex_Value2 = 0x102
                     49: Hex_Value2 = 0x103
                     50: 
                     51: [Non-alphanumerics_as_values]
                     52: ;Non-alpha numeric chars without quotes
                     53: Non_alpha1 = ;
                     54: Non_alpha2 = +
                     55: Non_alpha3 = *
                     56: Non_alpha4 = %
                     57: Non_alpha5 = <>
                     58: Non_alpha6 = @
                     59: Non_alpha7 = #
                     60: Non_alpha8 = ^
                     61: Non_alpha9 = -
                     62: Non_alpha10 = :
                     63: Non_alpha11 = ?
                     64: Non_alpha12 = /
                     65: Non_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: 
                     76: Non_alpha1_quotes = ";"
                     77: Non_alpha2_quotes = "+"
                     78: Non_alpha3_quotes = "*"
                     79: Non_alpha4_quotes = "%"
                     80: Non_alpha5_quotes = "<>"
                     81: Non_alpha6_quotes = "@"
                     82: Non_alpha7_quotes = "#"
                     83: Non_alpha8_quotes = "^"
                     84: Non_alpha9_quotes = "-"
                     85: Non_alpha10_quotes = "="
                     86: Non_alpha11_quotes = ":"
                     87: Non_alpha12_quotes = "?"
                     88: Non_alpha13_quotes = "/"
                     89: ;Non_alpha14_quotes = "\"
                     90: Non_alpha15_quotes = "&"
                     91: Non_alpha16_quotes = "{}"
                     92: Non_alpha17_quotes = "|"
                     93: Non_alpha18_quotes = "~"
                     94: Non_alpha19_quotes = "!"
                     95: ;Non_alpha20_quotes = "$"
                     96: Non_alpha21_quotes = "()"
                     97: 
                     98: [Non-alpha numerics in strings]
                     99: ;expected error, as the non-alphanumeric chars not enclosed in double quotes("")
                    100: Non_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]
                    124: Non_alpha_string1_quotes = "Hello@world"
                    125: Non_alpha_string2_quotes = "Hello!world"
                    126: Non_alpha_string3_quotes = "Hello#world"
                    127: Non_alpha_string4_quotes = "Hello&world"
                    128: Non_alpha_string5_quotes = "Hello*world"
                    129: Non_alpha_string6_quotes = "Hello+world"
                    130: Non_alpha_string7_quotes = "Hello-world"
                    131: Non_alpha_string8_quotes = "Hello'world"
                    132: Non_alpha_string9_quotes = "Hello:world"
                    133: Non_alpha_string10_quotes = "Hello;world"
                    134: Non_alpha_string11_quotes = "Hello<world"
                    135: Non_alpha_string12_quotes = "Hello>world"
                    136: Non_alpha_string13_quotes = "Hello>world"
                    137: Non_alpha_string14_quotes = "Hello?world"
                    138: Non_alpha_string15_quotes = "Hello\world"
                    139: Non_alpha_string16_quotes = "Hello^world"
                    140: Non_alpha_string17_quotes = "Hello_world"
                    141: Non_alpha_string18_quotes = "Hello|world"
                    142: Non_alpha_string19_quotes = "Hello~world"
                    143: Non_alpha_string20_quotes = "Hello`world"
                    144: Non_alpha_string21_quotes = "Hello(world)"
                    145: 
                    146: [Newlines_in_Values]
                    147: String1 = "Hello, world\nGood Morning"
                    148: String2 = "\nHello, world
                    149:              Good Morning\n"
                    150: String3 = 'Hello, world\tGood Morning'
                    151: String4 = "\n"
                    152: String5 = "\n\n"
                    153: String6 = Hello, world\tGood Morning
                    154: 
                    155: [ReservedKeys_as_Values]
                    156: Key1 = YES
                    157: Key2 = Yes
                    158: Key3 = yEs
                    159: Key4 = NO
                    160: Key5 = No
                    161: Key6 = nO
                    162: Key7 = TRUE
                    163: Key8 = True
                    164: Key9 = tRUE
                    165: Key10 = true
                    166: Key11 = FALSE
                    167: Key12 = False
                    168: Key13 = false
                    169: Key14 = fAlSE
                    170: Key15 = NULL
                    171: Key16 = Null
                    172: Key17 = nuLL
                    173: Key18 = 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
                    198: EOD;
                    199: /* creating parse.ini file */
                    200: $file_handle = fopen($file_path."/parse.ini", "w");
                    201: fwrite($file_handle, $parse_string);
                    202: fclose($file_handle);
                    203: 
                    204: echo "*** Test parse_ini_file() function:  with various keys and values given in parse.ini file ***\n";
                    205: echo "-- ini file without process_sections optional arg --\n";
                    206: define('BIRD', 'Humming bird');
                    207: $ini_array = parse_ini_file($file_path."/parse.ini");
                    208: print_r($ini_array);
                    209: 
                    210: echo "\n-- ini file with process_sections as TRUE --\n";
                    211: $ini_array = parse_ini_file($file_path."/parse.ini", TRUE);
                    212: print_r($ini_array);
                    213: 
                    214: echo "*** Done **\n";
                    215: ?>
                    216: --CLEAN--
                    217: <?php
                    218: unlink(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 --
                    223: Array
                    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
                    300: Good Morning
                    301:     [String2] => 
                    302: Hello, 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 --
                    333: Array
                    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
                    448: Good Morning
                    449:             [String2] => 
                    450: Hello, 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 **

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>