When do I use the PHP constant “PHP_EOL”?

前端 未结 19 2712
攒了一身酷
攒了一身酷 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条回答
  •  清歌不尽
    2020-11-22 07:10

    I found PHP_EOL very useful for file handling, specially if you are writing multiple lines of content into a file.

    For example, you have a long string that you want to break into the multiple lines while writing into plain file. Using \r\n might not work so simply put PHP_EOL into your script and the result is awesome.

    Check out this simple example below:

    
    

提交回复
热议问题