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