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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I get \r\n as newlines in text?

Status
Not open for further replies.

rrsub

MIS
Joined
Oct 23, 2002
Messages
536
Location
US
I'm outputting to a text file (MS .txt) and I get those newline characters that doesn't give newlines in MS notepad.

I don't want to do RTF because the end user will expect pretty text instead and it also will break pages.

OR

Is there a way to do BOLD text and select fonts in RTF and new pages in PHP without 3rd party software?
 
Since you are creating the new-lines you must know what they are. Right?
If you create all "\n" then just globally replace them with "\r\n" and you should be all set. Use str_replace() or a regular expression.

You can read about RTF format and use PHP to create such files, including page breaks (that's what I think you mean). However, that knowledge goes beyond the PHP forum.
 
Wether I do

"line1\nline2" or "line1\r\nline2"

still show up as line1[]line2

Keep in mind, I'm outputting (streaming) as a download file, not as a file in the web directory.

 
Next question then: have you selected an appropriate content type?
 
<?PHP
$filename = "test.txt";
include("createmessage.php"); //creates $text and $html

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

print $text;
?>

My initial need was for a csv and that works fine.
Now they will want output to a file like text. PDF and other formats will cost them because of hosting issues so plain text is fine.
 
Try:
header("Content-type: application/notepad");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top