How can the file size be accurately determined and used to empty a file in PHP?
To accurately determine the file size in PHP, you can use the `filesize()` function which returns the size of a file in bytes. To empty a file, you can use `file_put_contents()` with an empty string as the content parameter.
// Get the file size
$file = 'example.txt';
$fileSize = filesize($file);
// Empty the file
file_put_contents($file, '');
Keywords
Related Questions
- In what scenarios is it advisable to directly run SQL statements on the server instead of using PHP scripts for database operations?
- How can the PHP manual be utilized to better understand function usage in PHP?
- What are some best practices for handling data retrieval and manipulation in PHP scripts?