How can the issue of missing line breaks in a CSV file generated by PHP be resolved?
Issue: The missing line breaks in a CSV file generated by PHP can be resolved by adding "\r\n" at the end of each line to ensure proper formatting.
<?php
$data = array(
array('John', 'Doe', 'john.doe@example.com'),
array('Jane', 'Smith', 'jane.smith@example.com')
);
$fp = fopen('data.csv', 'w');
foreach ($data as $fields) {
fputcsv($fp, $fields);
fwrite($fp, "\r\n");
}
fclose($fp);
?>
Keywords
Related Questions
- What is the recommended method for updating a data record in a MySQL database using PHP?
- How can PHP programmers efficiently determine and display the winner in a game scenario like the one described in the forum thread?
- How can PHP arrays be effectively used to replace placeholders in template files with data from a database?