When do I use the PHP constant “PHP_EOL”?

前端 未结 19 2333
攒了一身酷
攒了一身酷 2020-11-22 06:21

When is it a good idea to use PHP_EOL?

I sometimes see this in code samples of PHP. Does this handle DOS/Mac/Unix endline issues?

19条回答
  •  旧时难觅i
    2020-11-22 07:01

    You use PHP_EOL when you want a new line, and you want to be cross-platform.

    This could be when you are writing files to the filesystem (logs, exports, other).

    You could use it if you want your generated HTML to be readable. So you might follow your
    with a PHP_EOL.

    You would use it if you are running php as a script from cron and you needed to output something and have it be formatted for a screen.

    You might use it if you are building up an email to send that needed some formatting.

提交回复
热议问题