Asim Zaidi
Asim Zaidi

Reputation: 28284

line break problem

I am forcing a text file download but I don't get a line break in the text file. It shows \r\n

header("Content-type: text/text");
header("Content-Disposition: attachment; filename=testi.txt");
foreach($results as $result){
echo $result['xrt'].' '.$result['CMP'].'    '.$result['Add'].' '.$result['AFG'].'   '.'Times'.' '.$result['range'].'\r\n';
}

Upvotes: 0

Views: 422

Answers (2)

Chris Laarman
Chris Laarman

Reputation: 1589

you need to use double quotes:

"\n\r"

check here for more info http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double

Upvotes: 1

Michael Robinson
Michael Robinson

Reputation: 29498

You could use PHP_EOL

header("Content-type: text/text");
header("Content-Disposition: attachment; filename=testi.txt");

foreach($results as $result){
    echo $result['xrt'].'   '.$result['CMP'].'  '.$result['Add'].' '.$result['AFG'].'   '.'Times'.' '.$result['range'].PHP_EOL;
}

Or if you must type them, use: "\r\n"

header("Content-type: text/text");
header("Content-Disposition: attachment; filename=testi.txt");

foreach($results as $result){
    echo $result['xrt'].'   '.$result['CMP'].'  '.$result['Add'].' '.$result['AFG'].'   '.'Times'.' '.$result['range']."\r\n";
}

Upvotes: 4

Related Questions