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