RE: [PHP] write_ini_file equivalent

From: Date: Sat, 26 Apr 2003 23:29:07 +0000
Subject: RE: [PHP] write_ini_file equivalent
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-145386@lists.php.net to get a copy of this message
here is what i do, its the only way rewrite the file again , using the variables as post vars so i can edit it in a form , there are sections laid out so i chek for a post variable then put the section before writing the variable function edit_ini_var($inifile,$update_table=null) { global $db; foreach ($_POST as $key=>$value) { if (preg_match("/domain_name/i",$key)) { $string .= "[gallery settings]\n$key=$value\n"; } elseif (preg_match("/thumbnail_width\b/i",$key)) { $string .= "\n[photo settings]\n$key=$value\n"; } elseif (preg_match("/cookie_domain\b/i",$key)) { $string .= "\n[cookie settings]\n$key=$value\n"; } elseif (preg_match("/admin_email\b/i",$key)) { $string .= "\n[registration settings]\n$key=$value\n"; } elseif (preg_match("/lost_password_subject\b/i",$key)) { $string .= "\n[email_message_settings]\n$key=$value\n"; } else { $string .= "$key=$value\n"; } } //if (!file_exists($inifile)) { // touch($inifile); //} $fp = @fopen($inifile, 'r+'); @flock($fp, LOCK_EX); @fwrite($fp, $string); @flock($fp, LOCK_UN); @fclose($fp); if ($update_table) { foreach ($_POST as $key=>$value) { $result = $db->query("UPDATE gallery_config SET config_value='$value' WHERE config_name='$key'"); } } } -----Original Message----- From: David T-G [mailto:davidtg-php@justpickone.org] Sent: Sunday, April 27, 2003 12:10 AM To: PHP General list Subject: [PHP] write_ini_file equivalent Hi, all -- In reading up on parse_ini_file, which looks like it will do what I want (though I've never liked the ini file format), I find that there is no corresponding write_ini_file function to write back my changes :-) My goal is to read in the ini file not only to construct my page but also to present to the user these variables ('name', 'bgcolor', 'phone', etcetc) for changes -- and then write it back. Do I need to whip up a function to walk through the array and write the sections and settings, or is there already something out there? TIA & HAND :-D -- David T-G * There is too much animal courage in (play) davidtg@justpickone.org * society and not sufficient moral courage. (work) davidtgwork@justpickone.org -- Mary Baker Eddy, "Science and Health" http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

« previous php.general (#145386) next »