Re: Updating parts of files without rewriting them
| From: | Fred | Date: | Sun, 02 Dec 2001 03:06:18 +0000 |
| Subject: | Re: Updating parts of files without rewriting them | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-76334@lists.php.net to get a copy of this message | ||
You cannot make changes to a file without writing the entire contents of the
file to disk. On the other hand, you do not need to manually re-create the
entire contents. Simple read the file into a variable and use regular
expressions to replace the old lines with new ones and then write the file
to disk. For what its worth, I cannot think of a justification for keeping
any settings other than database settings in a file. I would recommend
keeping all settings, other than database access settings, in a database.
This makes accessing and updating the settings much easier. The only reason
database settings must be in a file is because you obviously cannot access
the database without them (unless you use default settings in the php.ini
file).
Fred
Jeff Lewis <jeff@hyrum.net> wrote in message
news:002801c17ad9$7ec8b820$0100a8c0@cr983033a...
> I have a file that contains settings and there are a lot of comments in
> there and a lot of variables. An excerpt of the file looks like below.
My
> question is, is it possible to change only certain variables? For
example,
> I want to set just the db variables, is it possible for me to input the
new
> values in a form and replace only those in the file without having to
> rewrite the entire file?
>
> $mailtype = 0; # 0 - sendmail, 1 - SMTP
>
> ########## Database Info ##########
> $db_name = "name";
> $db_user = "user";
> $db_passwd = "pass";
> $db_server = "localhost";
>
> ########## Directories/Files ##########
> # Note: directories other than $imagesdir do not have to be changed unless
> you move things
>
> $boarddir = "."; # The absolute path to the folder (usually can be
left
> as '.')
> $sourcedir = "./Sources"; # Directory with source files
>
>