user2324069
user2324069

Reputation: 33

PHP include a text file whilst keeping carriage returns?

I have a text file that I'm including on my page, however the carriage returns aren't there as they are in the text document. How can I keep them as they are in the text document?

Upvotes: 0

Views: 529

Answers (2)

Mark Parnell
Mark Parnell

Reputation: 9215

Line breaks have no meaning in normal HTML (other than just being whitespace). You either need to convert them to HTML line breaks using nl2br(), or put the content of the text file in a <pre></pre> block.

Upvotes: 0

brbcoding
brbcoding

Reputation: 13586

$textfile = fopen('file.txt','r');
$readfile = fread($textfile); 
echo nl2br($readfile);

Upvotes: 1

Related Questions