Как записывать имя массива во время разбора ini-файла в PHP?

Я использую parse_ini_file для синтаксического анализа ini-файла с помощью PHP.

Теперь я сначала загружаю INI-файл на свой сервер, затем открываю его и разрешаю пользователю создавать пользовательские изменения в файле.

Теперь, когда пользователи отредактировали файл, я получаю данные из сообщения и сохраняю файл обратно на сервер. Но теперь я не получаю свои разделы. INIdetails, Dialplan в обновленном файле, поэтому, когда я также хочу написать, как это сделать?

Это код:

 $this->data['parameters'] = parse_ini_file($path.$filename,true); /*Getting Our POST DATA from View*/ $data = array( 'SipUserName' => $this->input->post('SipUserName') , 'SipAuthName' => $this->input->post('SipAuthName'), 'DisplayName' => $this->input->post('DisplayName'), 'Password' => $this->input->post('Password'), 'Domain' => $this->input->post('Domain'), 'Proxy' => $this->input->post('Proxy'), 'Port' => $this->input->post('Port'), 'ServerMode' => $this->input->post('ServerMode'), 'Param_1' => $this->input->post('Param_1'), 'Param_2' => $this->input->post('Param_2') ); /*Creating New file with the name of customer loggedin*/ $name = $this->session->userdata('username'); $ext = $this->session->userdata('extension'); $custom_file = fopen('uploads/'.$name.'_'.$ext.'.ini', 'w'); fwrite($custom_file, "[INIDetails]\n"); foreach ($data as $key => $value) { fwrite($custom_file, " $key = $value\n"); } fclose($custom_file); /*Setting path to New CUSTOM file with customer name as prefix*/ $file = $path.$custom_file; function write_php_ini($array, $file) { $res = array(); foreach($array as $key => $val) { if(is_array($val)) { $res[] = "[$key]"; foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"'); } else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"'); } safefilerewrite($file, implode("\r\n", $res)); } function safefilerewrite($fileName, $dataToSave) { if ($fp = fopen($fileName, 'w')) { $startTime = microtime(TRUE); do { $canWrite = flock($fp, LOCK_EX); // If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load if(!$canWrite) usleep(round(rand(0, 100)*1000)); } while ((!$canWrite)and((microtime(TRUE)-$startTime) < 5)); //file was locked so now we can store information if ($canWrite) { fwrite($fp, $dataToSave); flock($fp, LOCK_UN); } fclose($fp); } } /*Creates ini file, dumps array to string and creates .INI file*/ write_php_ini($data,$file); 

Related of "Как записывать имя массива во время разбора ini-файла в PHP?"