PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Surprisingly I can't find the answer to this anywhere. I want to be able to modify file contents using a form. Let's say I have a configuration file with
Along with other code. I would like to place each of the values into an array or seperate variables to load into a form for editing. I can probably figure out how to load them into the variable, but can't find how to append the data already in the file.
Well you can just include the config file, then modify only the ones modified in the form, then write back in the contents, to write back in the contents I recommend an array
I want the form to update the file using their settings so that all of the pages with the config file included will have the correct settings. I assume I would need to place each line of the config file into an array, loop through the array until it found the $server, $username, $password at the beginning of the array, change the value for each of those and then rewrite the config file with the new settings. Questions
1. Is that the easiest/best/only way to do this?
2. Is there a way to just rewrite a couple of lines in a file, or do I need to rewrite the entire file with the new settings.
I would like to do the same process for numerous things, i.e. editing css pages, I just can't find much information about appending the contents of a file, just adding to the file.
Brian3864 wrote:I want the form to update the file using their settings so that all of the pages with the config file included will have the correct settings. I assume I would need to place each line of the config file into an array, loop through the array until it found the $server, $username, $password at the beginning of the array, change the value for each of those and then rewrite the config file with the new settings. Questions
1. Is that the easiest/best/only way to do this?
easiest? by far
best? opinion
only? of course not
2. Is there a way to just rewrite a couple of lines in a file, or do I need to rewrite the entire file with the new settings.
Generally you would have to re-write the whole file, to avoid this turn to a DBMS; mysql for example