Skip to content
Advertisement

Output text file with line breaks in PHP

I’m trying to open a text file and output its contents with the code below. The text file includes line breaks but when I echo the file its unformatted. How do I fix this?

Thanks.

JavaScript

Advertisement

Answer

To convert the plain text line breaks to html line breaks, try this:

JavaScript

Note the nl2br function wrapping the text.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement