What are the best practices for handling the deletion of the last line in a CSV file in PHP to prevent the insertion of extra line breaks or empty lines?

When deleting the last line of a CSV file in PHP, it's important to ensure that no extra line breaks or empty lines are inserted. One way to handle this is by reading the file, removing the last line, and then writing the updated content back to the file without adding any additional line breaks.

<?php

// Read the CSV file into an array
$lines = file('file.csv');

// Remove the last line from the array
array_pop($lines);

// Write the updated content back to the file
file_put_contents('file.csv', implode('', $lines));

?>