-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathini_write.php
41 lines (35 loc) · 881 Bytes
/
ini_write.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
include_once 'mutex.php';
function ini_write($ini, $path, $has_sections=false) {
$content = "";
if ($has_sections) {
foreach ($ini as $key=>$section) {
$content .= "[".$key."]\n";
$content .= format_ini_section($section);
}
} else {
$content .= format_ini_section($ini);
}
$mutex = new Mutex($path);
if (!$handle = fopen($path, 'w')) {
return false;
}
$res = fwrite($handle, $content);
fclose($handle);
return $res;
}
function format_ini_section($section) {
$content = "";
foreach ($section as $key=>$elem) {
if (is_array($elem)) {
foreach ($elem as $array_elem) {
$content .= $key. "[] = \"" . $array_elem . "\"\n";
}
} elseif ($elem=="") {
$content .= $key . " = \n";
} else {
$content .= $key . " = \"" . $elem . "\"\n";
}
}
return $content;
}