我正在使用库来编写.ini格式的文件。
现在这是我的写作功能:
function write($file = NULL, $data = array(), $sections = TRUE) {
$this->data = (!empty($data)) ? $data : $this->data;
$this->file = ($file) ? $file : $this->file;
$this->sections = $sections;
$content = NULL;
if ($this->sections) {
foreach ($this->data as $section => $data) {
$content .= '[' . $section . ']' . PHP_EOL;
foreach ($data as $key => $val) {
if (is_array($val)) {
foreach ($val as $v) {
$content .= $key . '[] = ' . (is_numeric($v) ? $v : '"' . $v . '"') . PHP_EOL;
}
} elseif (empty($val)) {
$content .= $key . ' = ' . PHP_EOL;
} else {
$content .= $key . ' = ' . (is_numeric($val) ? $val : '"' . $val . '"') . PHP_EOL;
}
}
$content .= PHP_EOL;
}
} else {
foreach ($this->data as $key => $val) {
if (is_array($val)) {
foreach ($val as $v) {
$content .= $key . '[] = ' . (is_numeric($v) ? $v : '"' . $v . '"') . PHP_EOL;
}
} elseif (empty($val)) {
$content .= $key . ' = ' . PHP_EOL;
} else {
$content .= $key . ' = ' . (is_numeric($val) ? $val : '"' . $val . '"') . PHP_EOL;
}
}
}
return (($handle = fopen($this->file, 'w')) && fwrite($handle, trim($content)) && fclose($handle)) ? TRUE : FALSE;
}
我写了我的内容,我给这样的文件:
$file = $path.$filename;
$ini = new INI($file);
// Save settings to file
$ini->write($insert);
ON VAR_DUMP($ ini);我明白了:
object(INI)[76]
public 'file' => string 'C:/wamp/www/bizrtc/uploads/test1.ini' (length=36)
public 'data' =>
array (size=3)
'INIDetails' =>
array (size=11)
'SipUserName' => string '' (length=0)
'Password' => string '' (length=0)
'Domain' => string '' (length=0)
'Proxy' => string '' (length=0)
'Port' => string '' (length=0)
'SipAuthName' => string '' (length=0)
'DisplayName' => string '' (length=0)
'ServerMode' => string '' (length=0)
'UCServer' => string '' (length=0)
'UCUserName' => string '' (length=0)
'UCPassword' => string '' (length=0)
'DialPlan' =>
array (size=3)
'DP_Exception' => string '' (length=0)
'DP_Rule1' => string '' (length=0)
'DP_Rule2' => string '' (length=0)
'Advanced' =>
array (size=14)
'OperationMode' => string '' (length=0)
'MutePkey' => string '' (length=0)
'Codec' => string '' (length=0)
'PTime' => string '' (length=0)
'AudioMode' => string '' (length=0)
'SoftwareAEC' => string '' (length=0)
'EchoTailLength' => string '' (length=0)
'PlaybackBuffer' => string '' (length=0)
'CaptureBuffer' => string '' (length=0)
'JBPrefetchDelay' => string '' (length=0)
'JBMaxDelay' => string '' (length=0)
'SipToS' => string '' (length=0)
'RTPToS' => string '' (length=0)
'LogLevel' => string '' (length=0)
public 'sections' => boolean true
我哪里错了?我该怎么办才能让这个工作?
答案 0 :(得分:2)
如果没有错误的整个类和行号,则很难猜测。这个方法似乎没问题,至少是fopen的部分。对我来说,似乎你的财产已被其他地方覆盖。尝试将其设为私有,看看会发生什么,也许这有助于您发现问题。