How can empty lines be removed from a CSV file in PHP?

Empty lines in a CSV file can be removed in PHP by reading the file line by line, checking if each line is empty, and only writing non-empty lines to a new file. This can be achieved by using functions like `fopen`, `fgets`, and `fwrite`.

$inputFile = 'input.csv';
$outputFile = 'output.csv';

$in = fopen($inputFile, 'r');
$out = fopen($outputFile, 'w');

while (($line = fgets($in)) !== false) {
    if (trim($line) != '') {
        fwrite($out, $line);
    }
}

fclose($in);
fclose($out);

echo 'Empty lines removed from CSV file.';