Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Handling

Status
Not open for further replies.

VisBasDude

Programmer
Nov 10, 2002
19
GB
Hi, yeah i was wondering when i want to write records to a file but say in record 2 instead of at the end of the records then how is this best done. I am wanting to do this so that i can edit records after they have been created. Anyone got any ideas how its best to go about this? Thanx JP
 
This is how to open a file for reading and writing with the file position indicator at the end of the file.

$filePointer = fopen("mydata.txt", "a+")

To open for reading and writing at the start of the file use r+ instead of a+. Clive
 
How do i then tell the script where to write the details?
 
Does anyone have an example of this or know where a clear example is??
 
fseek() is clunky. Since you have to position the file pointer by bytes, you have to keep track of at which byte each line begines.

And since a file is a stream of records, if you write 20 bytes to a 15-byte line, you've just overwritten part of the next line.

[v]VisBasDude[/b]:
Do you have a database server available to you? MySQL or something? Modifying records via a database server is a lot easier than trying to reinvent it yourself. Want the best answers? Ask the best questions: TANSTAAFL!
 
Nah im using a file based system. Suppose i could create a temp file and put in the new data at the correct position and then just rename it! Do you think that would work?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top