Reputation: 6788
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?
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
Reputation: 89
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
Reputation: 59
Use the nl2br()
function:
echo nl2br("your first line\n your second line");
Upvotes: 1
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
Reputation: 48284
Some "fixes":
Use \r\n
for your line breaks to make Windows happy.
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