It's possible to ammend data within a file vs. just adding data to the beginning or the end of the file? Mean to change something in the "middle" of the file.
Thanks.
It's possible to ammend data within a file vs. just adding data to the beginning or the end of the file? Mean to change something in the "middle" of the file.
Thanks.
You can probably grep for the term you're looking for, obtain the line, then write to that line specifically, thus overwriting it. However, I've only ever used good old fwrite() so you'll have to check php.net for the right functions and statements - 'tis a great site though.
in my experience you can amend the data by reading the data into a variable
eg.
then you amend the data (i usually do it with forms so they are automaticaly filled and edited etc) and write it back into the file so the part you changed will be changed and the rest of the file will be consistent.Code:$var = readfile($file);
eg.
You want to change your username on a website. The file structure is like this
ID|Name|Email|Password
this allows you to split up the file into different segment with explode().
You can then populate a form with these values by using the array in which explode has created (need a loop for lots of users find the right userid etc etc) so if the user changes a field in there preferences box, eg. Name becomes Jack then i set it so if the data is changed within the textbox the restructured file is sent on submission of the form and your username is changed.
Seems well complicated if you dont get it, just ask a q..
There are currently 1 users browsing this thread. (0 members and 1 guests)