There is an ini file with the value

AdminLogin = admin 

How to overwrite a variable ini?

    2 answers 2

    I figured it out myself. First I get an array

     $conf = parse_ini_file('config.ini', true); $login = $conf['user']['AdminLogin']; 

    Then actually edit it

     $conf['user']['AdminLogin'] = $_POST['adminlogin']; 

    Next, I process the array with a function

     function arr2ini(array $a, array $parent = array()) { $out = ''; foreach ($a as $k => $v) { if (is_array($v)) { //subsection case //merge all the sections into one array... $sec = array_merge((array) $parent, (array) $k); //add section information to the output $out .= '[' . join('.', $sec) . ']' . PHP_EOL; //recursively traverse deeper $out .= arr2ini($v, $sec); } else { //plain key->value case $out .= "$k=$v" . PHP_EOL; } } return $out; } 

    And write to the file

      $inisave = arr2ini($conf); $file_handle = fopen("config.ini", "w"); fwrite($file_handle, $inisave); fclose($file_handle); 

      In general, no way. Solved only by complete rewriting of the file.

      Those. first read the file, got variables from it. One of them was changed and then again they wrote down all the variables in the file.

      • how to do it? - Sdafs Fasafs