开发者

CSV File as ASCII and with CRLF

开发者 https://www.devze.com 2023-03-30 04:30 出处:网络
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?

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'

0

精彩评论

暂无评论...
验证码 换一张
取 消