Solved

text file output not showing line breaks

Posted on 2003-12-04
3
243 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
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
lozloz earned 230 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses four methods for overlaying images in a container on a web page
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now