Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Header: Download Text File

Status
Not open for further replies.

iranor

Programmer
Jun 17, 2004
174
CA
<?
header("Content-Type: text/plain; name=file.txt");
header("Content-disposition: attachment; filename=file.txt");
echo "line1\nline2\nline3\nline4";
exit;
?>

The problem is, that when you download and open the file(with notepad) the whole text is on one line. Is there a way to make it so each line will be different?

I tried

<?
header("Content-Type: text/plain; name=file.txt");
header("Content-disposition: attachment; filename=file.txt");
echo "
line1
line2
line3
line4";
exit;
?>

Without success also. It's all on one line, and little squares splicing the different lines.
 
Did you try this:
header("Content-disposition: attachment; filename=file.txt");
header("Content-Type: text/plain;");
echo "line1\r\nline2\r\nline3\r\nline4";
 
Newline characters are different according to OS.
While it might not show linebreaks on a Windows machine it might show them on a Linux box. You should decide on the majprity of the target audience and provide the linbreaks for that OS.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top