Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

text file output not showing line breaks

Posted on 2003-12-04
3
Medium Priority
?
263 Views
Last Modified: 2013-11-18
Hi,

I’m trying to use the below code as an include for external text files. As such this is just normal paragraphs of text.

<?php
$filename = 'content.txt';
$fp = fopen($filename, "r");
$contents = fread($fp, filesize($filename));
fclose($fp);
echo $contents;
?>

My content.txt file (I used windows notepad looks like)
Line1
Line2
Line3
Line4

But for some reason, my output doesn’t have any line breaks. Instead it look like :

Line1 line2 line3 line4

Where am I going wrong?
0
Comment
Question by:fazsonet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
lozloz earned 920 total points
ID: 9874341
change echo $contents;

$contents = nl2br($contents);
echo $contents;

cheers,

loz
0
 

Author Comment

by:fazsonet
ID: 9874534
That was simple enough, although I couldn't seem to find it on the web somehow....
cheers,
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9874558
if you want to read up on it a bit more, i suggest you go to www.php.net/nl2br

cheers,

loz
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question