Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    I think there is a lot of misleading advice in the upvoted answers on this page. If you run a script on two different platforms, then compare the output or generated data (log files, html page, database records etc), then the PHP_EOL will result in a mismatch in the diff. In most cases this is not what you want. Commented Mar 15, 2018 at 14:08
  • 1
    I use PHP_EOL when writing scripts to execute and output in a command line terminal - so I know I can force a new line in text output in the terminal. For web applications I'd output <br> to force text to a new line (or wrap a block element around the content, like a paragraph or div). So I think answers should clarify the context of the PHP script (terminal application, web application, file creation script etc.) to support the argument for/against the use of PHP_EOL. Commented Jul 16, 2022 at 9:29
  • 1
    @MattSmith If you write a script, then you have to follow the script rules and not the end-of-line of the current system. If writing a bash script, then use \n, if you writing a windows script, then use \r\n. Both are independent from the current system and from PHP_EOL. Commented Sep 7, 2022 at 10:58
  • @Wiimm by "windows script" what do you mean? A PHP script that is running on Windows at the time? PHP_EOL will be the EOL for wherever it's running. I don't understand your comment. Commented Sep 16, 2024 at 4:34