Re: [PHP] updating several lines in a text file while leaving rest of file untouched
how much are they paying for their hosting? I mean seriously you can get a PHP enabled host that offers MySQL database for next to nothing these days. But, apart from that you could read the file into an array, making each line an element within the array. Modify what you need to modify, and then write the array back out to the file, overwriting it with the updated information. - Original Message - From: "Kurt Lieber" <[EMAIL PROTECTED]> To: "'Mark'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Monday, September 10, 2001 2:26 PM Subject: RE: [PHP] updating several lines in a text file while leaving rest of file untouched > agreed, except it's for a client who doesn't have database access at > their ISP and doesn't wish to pay more to get database access. So, I'm > stuck using a text file for now. > > --kurt > > > -Original Message- > > From: Mark [mailto:[EMAIL PROTECTED]] > > Sent: Monday, September 10, 2001 2:17 PM > > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > > Subject: Re: [PHP] updating several lines in a text file > > while leaving rest of file untouched > > > > > > On Mon, 10 Sep 2001 14:15:36 -0700, Kurt Lieber wrote: > > >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+"); file://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. > > > > you should seriously think about using a database for this. > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] updating several lines in a text file while leaving rest of file untouched
agreed, except it's for a client who doesn't have database access at their ISP and doesn't wish to pay more to get database access. So, I'm stuck using a text file for now. --kurt > -Original Message- > From: Mark [mailto:[EMAIL PROTECTED]] > Sent: Monday, September 10, 2001 2:17 PM > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Subject: Re: [PHP] updating several lines in a text file > while leaving rest of file untouched > > > On Mon, 10 Sep 2001 14:15:36 -0700, Kurt Lieber wrote: > >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. > > you should seriously think about using a database for this. > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] updating several lines in a text file while leaving rest of file untouched
On Mon, 10 Sep 2001 14:15:36 -0700, Kurt Lieber wrote: >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. you should seriously think about using a database for this. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] updating several lines in a text file while leaving rest of file untouched
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]