For reading ini files, you can use PHP's internal parse_ini_file function.
For reading configuration files like LoxBerry's general.cfg with
parse_ini_file, we recommend to use the scanner mode
INI_SCANNER_RAW as PHP may get problems trying to parse LoxBerry's settings.
For writing ini files with PHP you can use the included PHP library Config/Lite. It is included in Loxberry Core.
If you would like to use it, load it via
The usage is very simple. To load an ini file, use
INI_SCANNER_RAW should be used for read of different spells of boolean values. Otherwise booleans could be empty especially while writing the ini file.
If you wouldn't like to quote your values, disable quoting by
The LOCK_EX parameter above locks the file for writing.
Access values from the array
If your ini file is loaded, you have access to an array of your values:
You can set values to your ini file by writing to the array:
Slightly more complicated are boolean values like "on/off true/false". Most times the result will be wrong. For booleans there is an function getBool. More about the use of the included functions follows below.
Object orientated access
Another way to read/write are OO style functions
To read a value use
To set a value use
For booleans there is es special function called
getBool. This function returns a real bool and translates all possible values to it
You can also test if a value exists.
The return value is either
Save your changes
To save you values use
Visit the website of Config/Lite for documentation.