Solved

text file output not showing line breaks

Posted on 2003-12-04
3
253 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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

705 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