xZenjix Posted January 26, 2012 Share Posted January 26, 2012 Ok, so I have an INI file... OLD HTML= NEW HTML= I need to write the contents $oldhtml to "OLD HTML=" and the contents of $newhtml to "NEW HTML=" To store the contents of an ini file to a variable, I just used $config = parse_ini_file("config.ini",1); $email = $config['Email']; $host = $config['Host']; Cant I just write to the file by selecting ['Old HTML'] and ['NEW HTML'], in a fashion similar to the above code? Link to comment https://forums.phpfreaks.com/topic/255812-write-to-specific-area-of-an-ini-file-help/ Share on other sites More sharing options...
phpSensei Posted January 26, 2012 Share Posted January 26, 2012 From the Documentation: function write_ini_file($assoc_arr, $path, $has_sections=FALSE) { $content = ""; if ($has_sections) { foreach ($assoc_arr as $key=>$elem) { $content .= "[".$key."]\n"; foreach ($elem as $key2=>$elem2) { if(is_array($elem2)) { for($i=0;$i<count($elem2);$i++) { $content .= $key2."[] = \"".$elem2[$i]."\"\n"; } } else if($elem2=="") $content .= $key2." = \n"; else $content .= $key2." = \"".$elem2."\"\n"; } } } else { foreach ($assoc_arr as $key=>$elem) { if(is_array($elem)) { for($i=0;$i<count($elem);$i++) { $content .= $key2."[] = \"".$elem[$i]."\"\n"; } } else if($elem=="") $content .= $key2." = \n"; else $content .= $key2." = \"".$elem."\"\n"; } } if (!$handle = fopen($path, 'w')) { return false; } if (!fwrite($handle, $content)) { return false; } fclose($handle); return true; } Link to comment https://forums.phpfreaks.com/topic/255812-write-to-specific-area-of-an-ini-file-help/#findComment-1311352 Share on other sites More sharing options...
xZenjix Posted January 26, 2012 Author Share Posted January 26, 2012 I saw that - the problem I am confused with implementation. Link to comment https://forums.phpfreaks.com/topic/255812-write-to-specific-area-of-an-ini-file-help/#findComment-1311356 Share on other sites More sharing options...
phpSensei Posted January 26, 2012 Share Posted January 26, 2012 $sample= array( 'first' => array( 'first1' => 1, 'first2' => 2, 'first3' => 3, 'first4' => 4 ), 'second' => array( 'second1' => 1, 'second2' => 2, 'second3' => 3, 'second4' => 4 )); write_ini_file($sample, 'config.ini', true); Link to comment https://forums.phpfreaks.com/topic/255812-write-to-specific-area-of-an-ini-file-help/#findComment-1311358 Share on other sites More sharing options...
xZenjix Posted January 27, 2012 Author Share Posted January 27, 2012 Im sorry, Im confused. I dont have an array of text stored in a variable. I do have two variables though. Im new so im trying to piece it together but Im confused on where I put my $OldHTML and $NewHTML variables. Link to comment https://forums.phpfreaks.com/topic/255812-write-to-specific-area-of-an-ini-file-help/#findComment-1311542 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.