If you want to empty a file of it's contents bare in mind that opening a file in w mode truncates the file automatically, so instead of doing...
<?php
$fp = fopen("/tmp/file.txt", "r+");
ftruncate($fp, 0);
fclose($fp);
?>
You can just do...
<?php
$fp = fopen("/tmp/file.txt", "w");
fclose($fp);
?>