Solved

text file output not showing line breaks

Posted on 2003-12-04
3
247 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

809 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