Emptying file
Moderator: General Moderators
Emptying file
Is there any easy function for emptying files? If i have a file with some information, and want to erase all the info in it without unlink()'ing the file.? I can always read the name of the file, delete it and touch() a new one out of the info i got in a variable, but i'll rather not if theres any easier way.
well fopen can be used to truncate a file to 0 length... dunno how much that helps ya
http://www.php.net/manual/en/function.fopen.php
http://www.php.net/manual/en/function.fopen.php
Dont understand you 100% but this may help, If you are working with simple text files, It doesnt some much as empty, but in fact overwrites.
Hope it helps,
Phirus
Code: Select all
<?php
fopen("somefile.txt", "w");
?>Phirus
Found this: http://www.php.net/manual/en/function.ftruncate.php
I'll just read the lenght of the file and truncate the length
I'll just read the lenght of the file and truncate the length
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Phirus probably had the quickest way..
will just truncate it instantly.
Code: Select all
<?
$fp = fopen("somefile.txt", "w");
fclose($fp);
?>