Making CSV from PHP - Carriage return won't work

Posted by DMin on Stack Overflow See other posts from Stack Overflow or by DMin
Published on 2010-05-25T04:08:33Z Indexed on 2010/05/25 4:11 UTC
Read the original article Hit count: 420

Filed under:
|
|

Seems like a fairly simple issue but can't get it to work. I am getting the user to download a csv file(which works fine).

Basically I can't get the carriage return to work.

header("Content-type: text/x-csv");
header("Content-Disposition: attachment; filename=search_results.csv");
echo '"Name","Age"\n"Chuck Norris","70"';
exit;

Result : Name     Age\n"Chuck Norris"    70

Tried :

echo '"Name","Age",\n,"Chuck Norris","70"';

Result : Name     Age    \n    Chuck Norris    70

And

echo '"Name","Age",\n\r,"Chuck Norris","70"';

Result : Name     Age    \n\r    Chuck Norris    70

Know what's going wrong?

© Stack Overflow or respective owner

Related posts about php

Related posts about csv