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!
Moderator: General Moderators
jorgeng
Forum Commoner
Posts: 43 Joined: Mon Aug 04, 2008 8:05 am
Post
by jorgeng » Thu Aug 27, 2009 8:16 am
I have read an infile and need now emptying the indata
in file, meaning write back an empty file, how do i do
that in php without deleting the file and allocate it again?
Anyone has a good php code for this?
Mark Baker
Forum Regular
Posts: 710 Joined: Thu Oct 30, 2008 6:24 pm
Post
by Mark Baker » Thu Aug 27, 2009 8:35 am
Code: Select all
$fp = fopen($filename, 'r+');
$contents = fread($fp, filesize($filename));
rewind($fp);
fwrite($fp, '');
fclose($fp);
jorgeng
Forum Commoner
Posts: 43 Joined: Mon Aug 04, 2008 8:05 am
Post
by jorgeng » Mon Aug 31, 2009 7:51 am
Mark Baker wrote: Code: Select all
$fp = fopen($filename, 'r+');
$contents = fread($fp, filesize($filename));
rewind($fp);
fwrite($fp, '');
fclose($fp);
I don't know but it doesn't work.
The file is a txt-file with html-characters, does this matters?
09:45 ORDER "sl) Omx Wampa - Stega till Sekvens 9A Kl.09.45 - Okrypterat OMXS309I" kurs 912.7500$<br>09:45 ORDER "sl) Omx Wampa - Stega till Sekvens 9A Kl.09.45 - Okrypterat OMXS309I" kurs 913.0000$<br>10:00 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS309I" kurs 910.0000$<br>11:03 ORDER "sl) Omx Wampa Buystop - Kl.11 - Turkos - Okrypterat OMXS309I" kurs 913.2500$<br>14:11 ORDER "sl) Omx Wampa Sellstop - Kl.11 - Rosa - Okrypterat OMXS309I" kurs 907.2500$<br>14:11 ORDER "sl) Omx Wampa - Kurs Under Kl.11 Stapel Low - Eller Kl.17.20 OMXS309I" kurs 907.0000$<br>
Mark Baker
Forum Regular
Posts: 710 Joined: Thu Oct 30, 2008 6:24 pm
Post
by Mark Baker » Mon Aug 31, 2009 9:23 am
jorgeng wrote: I don't know but it doesn't work.
The file is a txt-file with html-characters, does this matters?
The content of the file should be irrelevant.
If that doesn't work, try:
Code: Select all
$fp = fopen($filename, 'r+');
$contents = fread($fp, filesize($filename));
ftruncate($fp, 0);
fclose($fp);
jorgeng
Forum Commoner
Posts: 43 Joined: Mon Aug 04, 2008 8:05 am
Post
by jorgeng » Mon Aug 31, 2009 9:28 am
Mark Baker wrote: jorgeng wrote: I don't know but it doesn't work.
The file is a txt-file with html-characters, does this matters?
The content of the file should be irrelevant.
If that doesn't work, try:
Code: Select all
$fp = fopen($filename, 'r+');
$contents = fread($fp, filesize($filename));
ftruncate($fp, 0);
fclose($fp);
Yes, that worked.
Thanks