How can PHP developers ensure that line breaks in CSV files are properly interpreted by Excel during import?

When exporting CSV files from PHP, developers should ensure that line breaks are properly encoded as "\r\n" to be interpreted correctly by Excel during import. This can be achieved by using the PHP function fputcsv() with the correct parameters to handle line breaks.

$csvData = array(
    array('Name', 'Age', 'Location'),
    array('John Doe', 30, 'New York'),
    array('Jane Smith', 25, 'Los Angeles'),
);

$fp = fopen('output.csv', 'w');

foreach ($csvData as $fields) {
    fputcsv($fp, $fields, ',', '"', "\r\n");
}

fclose($fp);