What are common methods in PHP to delete or clear a file before rewriting it?

When rewriting a file in PHP, it is common practice to delete or clear the file before writing new content to it. This ensures that the file does not contain any old data that might interfere with the new content being written. One common method to achieve this is to use the `file_put_contents()` function with an empty string as the content parameter, which effectively clears the file. Another method is to use the `unlink()` function to delete the file before rewriting it.

// Method 1: Clear the file before rewriting
file_put_contents('file.txt', '');

// Method 2: Delete the file before rewriting
if (file_exists('file.txt')) {
    unlink('file.txt');
}