parse_ini
array parse_ini (string initext [, bool changecase [,
bool convertwords]])
Parses the initext string (which is usually read from an
initialization file) and returns a multidimensional associative
array with section names and entry values. To generate an INI
string from an array, use generate_ini().
Differences from parse_ini_file()
This function is similar to parse_ini_file(). Since
the implementation of INI files in PHP is not the same as in
Windows, however, parse_ini() has the following
differences:
- The initext parameter is the string with the contents of
an INI file, not a file name.
- Sections are always processed.
- By default, the function changes the first character of all
section names to uppercase and leaves the others as lowercase,
and changes all entry names to lowercase. This behavior can be
changed by setting changecase to FALSE so section names and
entries are left as they are.
- A section may have no entry identifiers. In this case, the
section is read as a numeric array.
- Double-quotes ("") may optionally be used as string delimiters,
but they are not necessary.
- The following reserved words are automatically translated into
their values, unless convertwords is set to FALSE:
yes, on, true, no, off,
false, and null. Reserved words are not
case-sensitive.
- Any words (including the reserved words above) can be used as
entry identifiers.
- Constants are not parsed automatically. If you need to parse a
constant, use the constant() function.
Example
An example of a valid initext is below:
; Comments should start with ';'
[AppSettings] ; Comments are allowed after a section name
ShowWindow = true
Icon = 2 4
SiteURL = "http://winbinder.org"
forum = http://winbinder.org/forum
yes = true
[FILES] ; Entries with no identifiers are valid too
"main.ico"
"second#.ico"
OtherFiles = off
third.ico
|
Calling parse_ini() using the example above and the
default parameters will return the following array:
|
Array
(
[Appsettings] => Array
(
[showwindow]
=> 1
[icon]
=> 2 4
[siteurl]
=> http://winbinder.org
[forum]
=> http://winbinder.org/forum
[yes]
=> 1
)
[Files] => Array
(
[0]
=> main.ico
[1]
=> second#.ico
[otherfiles]
=> 0
[2]
=> third.ico
)
)
|
See also
generate_ini
Auxiliary
functions