?
Solved

text file output not showing line breaks

Posted on 2003-12-04
3
Medium Priority
?
258 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

770 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