.ini files and characters


It seems that some characters aren’t well appreciated when parsing such a file. I have a phrase using a “!” that I want to retrieve and it triggers an error.

Is there a way toa void that? Are XML files the only alternative to .ini?

Btw, I am trying to store a few text strings that I don’t want to have in a db.



Taken from the PHP.net manual :

Note: There are reserved words which must not be used as keys for ini files. These include: null, yes, no, true, and false. Values null, no and false results in “”, yes and true results in “1”. Characters {}|&~![()" must not be used anywhere in the key and have a special meaning in the value.

It seems like you can’t have the “!” character.

You can escape this by wrapping your string in double quotes, such as :

hello = “HELLO WORLD!”


Is there a way of using “ON” as a left-hand argument in an ini file?

This is a code for Ontario, Canada.

AB = Alberta
BC = “British Columbia”
MB = Manitoba
NB = “New Brunswick”
NL = “Newfoundland and Labrador”
NT = “Northwest Territories”
NS = “Nova Scotia”
NU = Nunavut
ON = Ontario
PE = “Prince Edward Island”
QC = Quebec
SK = Saskatchewan
YT = Yukon

No, not unless some common prefix is used for them.

The purpose of an ini file it to be as a configuration file, rather than a lookup table.

Why don’t you defines the values you want as an associated-key array? They can be placed in to a separate file, and read in when needed.

$region = array(
    'AB' => 'Alberta',
    'BC' => 'British Columbia',
    'MB' => 'Manitoba',

Thanks. I have done that before, but I was hoping to consolidate all settings and common values in one file. An .ini file seemed to be an ideal place.

I suppose an ugly work around for it would be to use the number zero instead of the O. But it would depend on how it is used. :stuck_out_tongue: