Andrew Danks Andrew Danks - 2 months ago 7x
PHP Question

Using a keyword as variable name in an INI file

I have the following in an INI file:

SE = Sweden
NO = Norway
FI = Finland

However, when var_dump()ing PHP's parse_ini_file() function, I get the following output:

PHP Warning: syntax error, unexpected BOOL_FALSE in test.ini on line 2
in /Users/andrew/sandbox/test.php on line 1

It appears that "NO" is reserved. Is there any other way I can set a variable named "NO"?


Another hack would be to reverse your ini keys with their values and use array_flip:


$ini =
    Sweden = 'SE'
    Norway = 'NO'
    Finland = 'FI'

$countries = parse_ini_string($ini, true);
$countries = array_flip($countries["country"]);
echo $countries["NO"];

Still you will need to use quotes around NO (at least), if you do

Norway = NO

you don't get an error but value for $countries["NO"] will be an empty string.