I need a CRLF (char10,cha开发者_如何学运维r(13) for each line in my csv file. The samples i found are not properly working. And i need the file in ASCII not UTF8. How can i save it as ASCII?
My code:
$fp = fopen('import.csv', 'w');
while ($daten = pg_fetch_assoc($query))
{
fputcsv($fp,$daten,chr(9));
}
You shouldnt need to manually put a CRLF at the end of each line when using fputcsv
However if you do actually want an "extra" line in between rows you could try this:
$fp = fopen('import.csv', 'w');
while ($daten = pg_fetch_assoc($query))
{
fputcsv($fp,$daten,chr(9));
fputs($fp,'\n');
}
fclose($fp);
Note that this is for linux ascii, if you want windows ascii it is '\r\n'
精彩评论