Tom Jacob Tom Jacob - 1 year ago 79
PHP Question

Why doesn't \n or PHP_EOL produce a new line in this online PHP compiler?

I have this very simple code:

"This is great".PHP_EOL."\r\nfoobar";

The code, however, does not insert a new line when I use the online IDE available at PhpFiddle, but it does work on the TutorialsPoint IDE.

The code does, however, do what I want and produce 2 new lines on PhpFiddle if I wrap the code with html tags.

What is the difference in the implementation of these two IDEs?

Answer Source

You are apparently mixing up 2 things:

  1. HTML output
  2. CLI output

The \r\n characters are only correctly displayed when you run your PHP script in CLI mode.

As, I would say, 99% use PHP for Web Applications these characters are ignored. Use instead the HTML tags. For example <br /> for a new line.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download