question about replacing certain items in a file on the fly
Posted: Wed Sep 28, 2005 1:25 pm
I have a config file. It looks like this.
I have a form where a user can give new integer values for the items defined above.
e.g. after posting the form, I have something like:
I am wondering, how would I read through config.php line by line, and on each line, change the value of the defined thing to the new value as specified by the user's form?
I'm figuring it's going to be some king of ereg_replace type thing but I'm really horrible at regex, and also I wasnt' sure what the best way is to read through a file line by line, if I should be using fgets() or just file().
Thanks.
Code: Select all
config.php
<?
define('BOX_X', 22);
define('BOX_Y', 12);
define('BOX_WIDTH', 114);
define('BOX_HEIGHT', 27);
define('ENVELOPE_WIDTH', 240);
define('DESIRED_MARGIN', 13);
?>I have a form where a user can give new integer values for the items defined above.
e.g. after posting the form, I have something like:
Code: Select all
Array
(
[BOX_X] => 35
[BOX_Y] => 15
[BOX_WIDTH] => 127
[BOX_HEIGHT] => 30
[ENVELOPE_WIDTH] => 200
[DESIRED_MARGIN] => 10
[submit] => Submit Changes
)I'm figuring it's going to be some king of ereg_replace type thing but I'm really horrible at regex, and also I wasnt' sure what the best way is to read through a file line by line, if I should be using fgets() or just file().
Thanks.