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