0

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'; } 
1
  • No, "\r\n" would do it. PHP_EOL changes depending on which plattform your script get's executed. If it's a linux based server it will contain "\n" but if it's your windows testbed it will be "\r\n". So keep it save and use "\r\n". Otherwise you might get surprises when you move your site from one server to another. Commented Jun 8, 2011 at 21:42

2 Answers 2

4

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"; } 
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.