-
Notifications
You must be signed in to change notification settings - Fork 0
/
ini.php
executable file
·41 lines (36 loc) · 1.04 KB
/
ini.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/* ini.php
* a set of functions to read ini files
*
*
* $ini = new ini('filename');
* - opens a new ini file
*
* $ini->list(section);
* - returns all items in a section
*
* $ini->read(section, item);
* - reads the selected item
*/
function ini2array($FILE) {
// check if the file exists
if (!is_file($FILE)) {
return Array();
}
// read the file into memory
$DATA = file_get_contents($FILE);
// read the data into an array
foreach (explode("\n", $DATA) as $LINE) {
// remove any whitespace / return carriage
$LINE = trim($LINE);
if ((substr($LINE, 0, 1) == "[") && (substr($LINE, strlen($LINE) - 1) == "]")) {
// assume this is a [section]
$SECTION = substr($LINE, 1, -1);
} elseif (strpos($LINE, '=') != "") {
// assume this is a item=value
$INI[$SECTION][substr($LINE, 0, strpos($LINE, '='))] = substr($LINE, strpos($LINE, '=') + 1);
}
}
return $INI;
}
?>