|
Posted by BT3 on 05/12/05 04:48
I am trying to replace a single record in a flat file. The file is
relatively small and no need for database.
I open the file, and save the ftell() value in a variable.
I read a record using fgetcsv(), modify the index contents it if/as
necessary.
I then position the pointer back to the beginning of that record using
fseek(value_from_ftell).
I build a new string with the required delimiters.
Finally I put the record with fputs() (also fails with fwrite()).
What the code actually does, is append a NEW record to the end. Can't seem
to find out hot to REPLACE the original record with the new data.
Code:
---------
$fp = fopen('filename');
$filerec = ftell($fp);
-->for...next
$user = fgetcsv($fp, 999, "\t");
/*
Code here to change as required $user[0-6]
*/
$outputstr = $user[0]."\t".$user[1]."\t". etc, etc
fseek($filerec);
fputs($fp, $outputstr);
-->next
fclose($fp);
Thanks, bt3
Navigation:
[Reply to this message]
|