Quantcast
Viewing all articles
Browse latest Browse all 21

Line-feed is identified as Windows style, despite using \n

I'm creating on-the-fly a CSV file to download via a hyperlink, using the following code:

                $content = <<<ENDdata:text/csv;charset=utf-8,\xEF\xBB\xBF"Date","Number of items sold","Number of orders","Average net sales amount","Coupon amount","Shipping amount","Gross sales amount","Net sales amount","Refund amount"\n"2022-4-26","0","0","7.82","0.00","0.00","0.00","0.00","0.00"\n"2022-4-27","0","0","0","0.00","0.00","0.00","0.00","0.00"\n"2022-4-28","0","0","0","0.00","0.00","0.00","0.00","0.00"\n"2022-4-29","3","3","0","0.00","9.00","63.73","54.73","0.00"\n"2022-4-30","0","0","0","0.00","0.00","0.00","0.00","0.00"\n"2022-5-1","0","0","0","0.00","0.00","0.00","0.00","0.00"\n"2022-5-2","0","0","7.82","0.00","0.00","0.00","0.00","0.00"\nEND;                $link = '<a href="' . htmlspecialchars($content, ENT_QUOTES) . '">' . __('Download CSV', 'custom-code') . '</a>';

The problem is that although I'm using \n at the end of each line, the produced file is still identified as having CRLF style of new lines.

Here you can find two files, where report-7day-2022-05-02.csv is created by JS and is identified correctly as LF, and aaaaaa.csv is my file - created by the code above - and is somehow mistakenly identified as CRLF.

What am I doing wrong?


Viewing all articles
Browse latest Browse all 21

Trending Articles