IniParser

This is a simple class to parse INI files.

Summary
IniParserThis is a simple class to parse INI files.
Functions
readFileRead the contents of an INI file into a two-dimensional array.
getFileSerializes the INI file into a string.
writeFileWrite the INI file back to the disk.
valueGet a value from the INI file.
valueIsSetDetermine if a particular key has been set.
setValueSets a value for a key.
getSectionReturns the given section as an array.
getSectionNamesGets a list of the section names available in the file.
mergeMerge another INI file into the current one.

Functions

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($file = false)

Write the INI file back to the disk.

Parameters

fileThe filename to write to.  Defaults to the filename property.

Returns

True if the write succeeds, false otherwise.

value

function value($sec,  
$var = false,
$default = false)

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,  
$var = false)

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,  
$val = false)

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

secThe 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

fileThe INIParser object to merge with the current object.
function readFile()
Read the contents of an INI file into a two-dimensional array.
function getFile()
Serializes the INI file into a string.
function writeFile($file = false)
Write the INI file back to the disk.
function value($sec,  
$var = false,
$default = false)
Get a value from the INI file.
function valueIsSet($sec,  
$var = false)
Determine if a particular key has been set.
function setValue ($sec,  
$var,  
$val = false)
Sets a value for a key.
function getSection($sec)
Returns the given section as an array.
function getSectionNames()
Gets a list of the section names available in the file.
function merge($file)
Merge another INI file into the current one.
Close