Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fputcsv and Notepad

Tags:

php

csv

I generate csv files with fputcsv and it works just fine, but when I view the csv file in Notepad (Windows) there is no new lines. All lines are in just 1 line, and where the linebreak is supposed to be, there is a sqaure (corrupted character). Other editors on Mac for example show the lines with breaks correctly.

Is there any way to fix this problem as the CSV needs to be imported, and the importer does not see the linebreaks as well.

like image 240
rkj Avatar asked Sep 21 '26 05:09

rkj


1 Answers

http://bugs.php.net/bug.php?id=46367

This is a known and unfixed bug in PHP.

Until they fix it, try using fwrite($fp, '"'.implode('","', str_replace('"', '""', $data_array)).'"'.PHP_EOL);

like image 94
reukiodo Avatar answered Sep 23 '26 20:09

reukiodo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!