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

Carriage returns to new paragraphs

Status
Not open for further replies.

buzzt

Programmer
Joined
Oct 17, 2002
Messages
171
Location
CA
I have several text documents which I want to include (include("file.txt")) in my php. How would I make the carriage returns in the text file be read as either line breaks or new paragraphs (so I don't have to add any HTML tags) when I include them in a php page?
 
if u don't want to put the <br>s in the text file, u can't include it. u'll have to fopen it to put the <br>s, like:

$file = &quot;txt.txt&quot;;
$f = fopen($file,&quot;r&quot;);
$content = fread($f, filesize($file));
fclose($f);

and then
$content = nl2br($content);

now you have it ready to display, just echo it

echo $contents;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top