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 = \
63;These chars have a special meaning when used in the value,
64;  hence parser throws an error
65;Non_alpha13 = &
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_alpha1_quotes] => ;
248    [Non_alpha2_quotes] => +
249    [Non_alpha3_quotes] => *
250    [Non_alpha4_quotes] => %
251    [Non_alpha5_quotes] => <>
252    [Non_alpha6_quotes] => @
253    [Non_alpha7_quotes] => #
254    [Non_alpha8_quotes] => ^
255    [Non_alpha9_quotes] => -
256    [Non_alpha10_quotes] => =
257    [Non_alpha11_quotes] => :
258    [Non_alpha12_quotes] => ?
259    [Non_alpha13_quotes] => /
260    [Non_alpha15_quotes] => &
261    [Non_alpha16_quotes] => {}
262    [Non_alpha17_quotes] => |
263    [Non_alpha18_quotes] => ~
264    [Non_alpha19_quotes] => !
265    [Non_alpha21_quotes] => ()
266    [Non_alpha_string1] => Hello@world
267    [Non_alpha_string1_quotes] => Hello@world
268    [Non_alpha_string2_quotes] => Hello!world
269    [Non_alpha_string3_quotes] => Hello#world
270    [Non_alpha_string4_quotes] => Hello&world
271    [Non_alpha_string5_quotes] => Hello*world
272    [Non_alpha_string6_quotes] => Hello+world
273    [Non_alpha_string7_quotes] => Hello-world
274    [Non_alpha_string8_quotes] => Hello'world
275    [Non_alpha_string9_quotes] => Hello:world
276    [Non_alpha_string10_quotes] => Hello;world
277    [Non_alpha_string11_quotes] => Hello<world
278    [Non_alpha_string12_quotes] => Hello>world
279    [Non_alpha_string13_quotes] => Hello>world
280    [Non_alpha_string14_quotes] => Hello?world
281    [Non_alpha_string15_quotes] => Hello\world
282    [Non_alpha_string16_quotes] => Hello^world
283    [Non_alpha_string17_quotes] => Hello_world
284    [Non_alpha_string18_quotes] => Hello|world
285    [Non_alpha_string19_quotes] => Hello~world
286    [Non_alpha_string20_quotes] => Hello`world
287    [Non_alpha_string21_quotes] => Hello(world)
288    [String1] => Hello, world
289Good Morning
290    [String2] =>
291Hello, world
292             Good Morning
293
294    [String3] => Hello, world	Good Morning
295    [String4] =>
296
297    [String5] =>
298
299
300    [String6] => Hello, world	Good Morning
301    [Key1] => 1
302    [Key2] => 1
303    [Key3] => 1
304    [Key4] =>
305    [Key5] =>
306    [Key6] =>
307    [Key7] => 1
308    [Key8] => 1
309    [Key9] => 1
310    [Key10] => 1
311    [Key11] =>
312    [Key12] =>
313    [Key13] =>
314    [Key14] =>
315    [Key15] =>
316    [Key16] =>
317    [Key17] =>
318    [Key18] =>
319)
320
321-- ini string with process_sections as TRUE --
322Array
323(
324    [Constans] => Array
325        (
326            [one] => 1
327            [five] => 5
328            [animal] => Humming bird
329            [Language] => PHP
330            [PHP_CONSTANT] => 1.2345678
331            [10] => Ten
332            [HELLO] => HELLO
333        )
334
335    [date] => Array
336        (
337            [date] =>
338            [time] =>
339        )
340
341    [paths] => Array
342        (
343            [path] => /usr/local/bin
344            [URL] => http://www.php.net
345        )
346
347    [Decimal] => Array
348        (
349            [Decimal_value1] => 100
350            [Decimal_value2] => -100
351            [Decimal_value3] => -2147483647
352            [Decimal_value4] => 2147483647
353            [Decimal_value5] => -2147483648
354            [Decimal_value6] => 2147483648
355        )
356
357    [Octal] => Array
358        (
359            [Octal_value] => 0100
360        )
361
362    [Hex] => Array
363        (
364            [Hex_value1] => 0x101
365            [Hex_Value2] => 0x103
366        )
367
368    [Non-alphanumerics_as_values] => Array
369        (
370            [Non_alpha1] =>
371            [Non_alpha2] => +
372            [Non_alpha3] => *
373            [Non_alpha4] => %
374            [Non_alpha5] => <>
375            [Non_alpha6] => @
376            [Non_alpha7] => #
377            [Non_alpha8] => -
378            [Non_alpha9] => :
379            [Non_alpha10] => ?
380            [Non_alpha11] => /
381            [Non_alpha12] => \
382            [Non_alpha1_quotes] => ;
383            [Non_alpha2_quotes] => +
384            [Non_alpha3_quotes] => *
385            [Non_alpha4_quotes] => %
386            [Non_alpha5_quotes] => <>
387            [Non_alpha6_quotes] => @
388            [Non_alpha7_quotes] => #
389            [Non_alpha8_quotes] => ^
390            [Non_alpha9_quotes] => -
391            [Non_alpha10_quotes] => =
392            [Non_alpha11_quotes] => :
393            [Non_alpha12_quotes] => ?
394            [Non_alpha13_quotes] => /
395            [Non_alpha15_quotes] => &
396            [Non_alpha16_quotes] => {}
397            [Non_alpha17_quotes] => |
398            [Non_alpha18_quotes] => ~
399            [Non_alpha19_quotes] => !
400            [Non_alpha21_quotes] => ()
401        )
402
403    [Non-alpha numerics in strings] => Array
404        (
405            [Non_alpha_string1] => Hello@world
406        )
407
408    [Non-alpha numerics in strings -with quotes] => Array
409        (
410            [Non_alpha_string1_quotes] => Hello@world
411            [Non_alpha_string2_quotes] => Hello!world
412            [Non_alpha_string3_quotes] => Hello#world
413            [Non_alpha_string4_quotes] => Hello&world
414            [Non_alpha_string5_quotes] => Hello*world
415            [Non_alpha_string6_quotes] => Hello+world
416            [Non_alpha_string7_quotes] => Hello-world
417            [Non_alpha_string8_quotes] => Hello'world
418            [Non_alpha_string9_quotes] => Hello:world
419            [Non_alpha_string10_quotes] => Hello;world
420            [Non_alpha_string11_quotes] => Hello<world
421            [Non_alpha_string12_quotes] => Hello>world
422            [Non_alpha_string13_quotes] => Hello>world
423            [Non_alpha_string14_quotes] => Hello?world
424            [Non_alpha_string15_quotes] => Hello\world
425            [Non_alpha_string16_quotes] => Hello^world
426            [Non_alpha_string17_quotes] => Hello_world
427            [Non_alpha_string18_quotes] => Hello|world
428            [Non_alpha_string19_quotes] => Hello~world
429            [Non_alpha_string20_quotes] => Hello`world
430            [Non_alpha_string21_quotes] => Hello(world)
431        )
432
433    [Newlines_in_Values] => Array
434        (
435            [String1] => Hello, world
436Good Morning
437            [String2] =>
438Hello, world
439             Good Morning
440
441            [String3] => Hello, world	Good Morning
442            [String4] =>
443
444            [String5] =>
445
446
447            [String6] => Hello, world	Good Morning
448        )
449
450    [ReservedKeys_as_Values] => Array
451        (
452            [Key1] => 1
453            [Key2] => 1
454            [Key3] => 1
455            [Key4] =>
456            [Key5] =>
457            [Key6] =>
458            [Key7] => 1
459            [Key8] => 1
460            [Key9] => 1
461            [Key10] => 1
462            [Key11] =>
463            [Key12] =>
464            [Key13] =>
465            [Key14] =>
466            [Key15] =>
467            [Key16] =>
468            [Key17] =>
469            [Key18] =>
470        )
471
472    [ReservedKeys_as_Keys] => Array
473        (
474        )
475
476)
477*** Done **
478