RE: [PHP] read/write ini file
| From: | Dan Rossi | Date: | Tue, 15 Apr 2003 22:33:28 +0000 |
| Subject: | RE: [PHP] read/write ini file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144027@lists.php.net to get a copy of this message | ||
did my thread just get hijacked ?
i have the ini settings setup the same names as the form fields when i
submit the changes, here is something i'm trying to sort out
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";
}
}
even though u can easily read the file i'm keeping the settings in the db ,
then read them back to the form to remake the ini file , yes only way i can
sort out making changes here is the unlink the file and make a new one.
-----Original Message-----
From: David T-G [mailto:davidtg-php@justpickone.org]
Sent: Tuesday, April 15, 2003 10:11 PM
To: PHP General list
Cc: John W. Holmes
Subject: Re: [PHP] read/write ini file
John, et al --
...and then John W. Holmes said...
%
% > hi there i am considering of using the db/ini file to store global
% > settings
% > which some values will get stored into constants , how can i possible
% read
% > write from the ini blocks like so
%
% Reading is easy, just use parse_ini_file().
Hey, cool. I like that even better than our current include()ing.
If I parse multiple ini files, will a setting in the last one override a
setting in the earlier ones, or do I need to parse in reverse because it
keeps the first one it reads? [Yes, I know I should test it and see, but
I don't even have some sample code written yet :-]
%
% Writing isn't that difficult, either. I wrote a simple class that'll
% read and write ini files by replacing the
%
% Variable = value
I'm not so worried about writing the values back out, but I haven't yet
found a way to preserve the comments and layout. That is, a file like
...
; the path is where you walk
path = /this/path:/that/path
; size is the finished size
size = 640
; i could go on all day about this part. really.
; i even tend to ramble. but comments are important!
important = very
; oh, yeah -- now we continue
done = finally
...
will only give me $path $size $important $done and not any of the
comments or even the order in which the settings are specified... Any
hope of preserving that?
%
% Lines with text boxes and wrapping a form tag around them all. Let me
% know if you'd like to see it.
Love to :-) I'm working my way toward a config web page where users can
change their stuff, and writing the comments back sure would be nice. [I
suppose I could alternatively embed the comments in the web page script,
but that doesn't help someone who is editing the ini file manually.]
%
% ---John W. Holmes...
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!