Annotation of embedaddon/php/ext/standard/tests/general_functions/parse_ini_string_001.phpt, revision 1.1

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

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