JM4
JM4

Reputation: 6788

How to resolve PHP PHP_EOL issue

the constant:

PHP_EOL

is supposed to represent a line break on both windows and linux, however when I run on my linux box there is no spacing (has caused major headaches generating .txt files that now have boxes instead of line breaks).

Any quick fix to the issue?

EDIT

It seems the common answer is that anything created on the Linux machine will not 'appear' correctly within notepad. Is there any to correct this on the back end within notepad itself(a find and replace per say and replace with an actual break?)

Upvotes: 5

Views: 20743

Answers (4)

You can read text log file to html with line break. This works in Windows and Linux/Unix:

echo str_replace("\n", '<br>', file_get_contents($logfilename));

Upvotes: 0

ahmad almasri
ahmad almasri

Reputation: 59

Use the nl2br() function:

echo nl2br("your first line\n your second line"); 

Upvotes: 1

jrn.ak
jrn.ak

Reputation: 36619

Don't use PHP_EOL for text-file output.

IIRC it's better to use "\r\n" for best compatibility.

You can DEFINE or $var it if you want.

Upvotes: 9

Matthew
Matthew

Reputation: 48284

Some "fixes":

  1. Use \r\n for your line breaks to make Windows happy.

  2. Don't use notepad.

PHP_EOL only represents something per the system it's running on. It cannot possibly simultaneously represent every EOL sequence that each OS uses.

Upvotes: 13

Related Questions