\n not creating a new line in downloadable text file
Posted: Mon Jun 01, 2009 3:21 pm
I am trying to present a text file for the user to download. This text file is dynamicaly created using php based on user input. It is supposed to span several lines but it is just sticking everything on one line. Here is the code:
What I want to get is a text file like this:
Hello
How are you?
It is nice weather(USER INPUT)
But I am getting this:
HelloHow are you?It is nice weather(USER INPUT)
If I get rid of the then it works but it is just displayed in the browser and I want a downloadable file. Does anyone know why this is happening.
Appreciate any help. Thanks.
Code: Select all
<?php
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="hello.txt"');
echo "Hello\nHow are you?\nIt is nice weather" . $_POST['text'];
?>
Hello
How are you?
It is nice weather(USER INPUT)
But I am getting this:
HelloHow are you?It is nice weather(USER INPUT)
If I get rid of the
Code: Select all
header('Content-Disposition: attachment; filename="hello.txt"');Appreciate any help. Thanks.