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