Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a file named file.txt that looks like this:

  1. Line 1
  2. Line 2
  3. Line 3
  4. Line 4

using the command:

$content = file_get_contents(file.txt);

echo $content

I get the output on one line:

Line 1 Line 2 Line 3 Line 4

How can I get the output printed over 4 lines?

share|improve this question

closed as not a real question by Diogo, Mokubai, 8088, Journeyman Geek, Renan Jul 23 '12 at 23:23

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 0 down vote accepted

If you print it in your browser it will read it as html and not display line breaks unless you use <br> tags for it. Try this:

$content = file_get_contents(file.txt);
$content = ln2br($content); // Converts line breaks to html <br> tags
echo $content;

If it doesn't work, try:

$content = file_get_contents(file.txt);
echo '<pre>';
echo $content;
echo '</pre>';

and you'll see line breaks.

share|improve this answer
    
'<pre>' works perfectly for what I'm looking to do. Thanks! –  Matt Stokes Jul 24 '12 at 15:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.