Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 off topic by Bruno Pereira Jul 23 '12 at 21:22

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

If you are outputting HTML, you can wrap it in a <pre>.

If you do not need HTML but you are using HTTP, you can change the mime-type by using header(). For example, change it to text/plain.

If you want the line breaks visible, but do not want to use <pre>, you can convert them to HTML line breaks by using nl2br().

share|improve this answer
'<pre>' works perfectly! – Matt Stokes Jul 24 '12 at 15:56

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