You are here: Replacing a record in a flat file « PHP Programming Language « IT news, forums, messages
Replacing a record in a flat file

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация