updating several lines in a text file while leaving rest of file untouched

From: Date: Mon, 10 Sep 2001 21:15:36 +0000
Subject: updating several lines in a text file while leaving rest of file untouched
Groups: php.general 
Request: Send a blank email to php-general+get-66815@lists.php.net to get a copy of this message
I have a configuration file that I use to store several variables and would like to provide a web-based interface to update this form. I'm having some trouble replacing part of the file while leaving the rest of it intact. An example of the config file is: $eventInfo[1][1] = "First Event Title"; $eventInfo[1][2] = 145; $eventInfo[1][3] = 300; $eventInfo[2][1] = "Second Event Title"; $eventInfo[2][2] = 50; $eventInfo[2][3] = 1500; What I can't figure out is how to selectively update certain lines, while leaving all the other lines intact and without changing the structure or order of the page. So, if I wanted to change $eventInfo[1][2] to 150 and $eventInfo[2][3] to 2000, how can I do that without mucking up the rest of the page? I can update any one line by using something like the following: $fd = fopen($configFile, "r+"); //open the file and truncate it. $newContents = eregi_replace("eventInfo\[1\]\[1\] = \".*\";","eventInfo[1][1] = \"" . $form_eventTitle . "\";",$contents); $newFile = fwrite($fd,$newContents); but if I try to update more than one line, it causes the rest of my file to get truncated or other weird things to happen. Any help is appreciated. --kurt

« previous php.general (#66815) next »