IniParser
IniParser

This is a simple class to parse INI files.

Functions
fromArray
public static function fromArray(
array $ini_array,
$filename null,
$fs null
)

Converts an associative array into an INIParser object

readFile
function readFile()

Read the contents of an INI file into a two-dimensional array.  This method preserves comments in the file.

getFile
function getFile()

Serializes the INI file into a string.

Returns

The INI file structure as a string that can be written to a file.

writeFile
function writeFile(
$filefalse
)

Write the INI file back to the disk.

Parameters
file

The filename to write to.  Defaults to the filename property.

Returns

True if the write succeeds, false otherwise.

value
function value(
$sec,
$varfalse,
$defaultfalse
)

Get a value from the INI file.

Parameters

Takes up to three parameters.  If one parameter is given, then it is interpreted as a key in the current section (last section accessed).  If two are given, the first is a section and the second is a key.  If three, then the first is the section, the second is the key, and the third is a default value if the key is not set.

Returns

A string containing the value of the given key, or the default value.

valueIsSet
function valueIsSet(
$sec,
$varfalse
)

Determine if a particular key has been set.

Parameters

This can take one or two parameters.  If one is given, it is a key in the current section.  If two, the first is a secion and the second is a key.

Returns

True if the given key has been set, false otherwise.

setValue
function setValue (
$sec,
$var,
$valfalse
)

Sets a value for a key.

Parameters

Takes two or three parameters.  If two, then the first is a key in the current section and the second is a value.  If three, then the first is a section, the second a key, and the third the value.

Returns

The value to which the key was set.

getSection
function getSection(
$sec
)

Returns the given section as an array.  Removes any comments from that section of the file.

Parameters
sec

The section of the file to get.

Returns

An array of the section with variables as keys and values as elements.

getSectionNames
function getSectionNames()

Gets a list of the section names available in the file.

Returns

An array of strings, each of which is the name of a section.

merge
function merge(
$file
)

Merge another INI file into the current one.  If a key from the other file is not set, it will be set with the value from the other file.  Keys that are already set will not be modified.

Parameters
file

The INIParser object to merge with the current object.