Emptying data infile

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

Post Reply
jorgeng
Forum Commoner
Posts: 43
Joined: Mon Aug 04, 2008 8:05 am

Emptying data infile

Post by jorgeng »

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

Re: Emptying data infile

Post by Mark Baker »

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

Re: Emptying data infile

Post by jorgeng »

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

Re: Emptying data infile

Post by Mark Baker »

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

Re: Emptying data infile

Post by jorgeng »

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
:wink:
Post Reply