When do I use the PHP constant “PHP_EOL”?

前端 未结 19 2726
攒了一身酷
攒了一身酷 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:15

    There is one obvious place where it might be useful: when you are writing code that predominantly uses single quote strings. Its arguable as to whether:

    echo 'A $variable_literal that I have'.PHP_EOL.'looks better than'.PHP_EOL;  
    echo 'this other $one'."\n";
    

    The art of it is to be consistent. The problem with mix and matching '' and "" is that when you get long strings, you don't really want to have to go hunting for what type of quote you used.

    As with all things in life, it depends on the context.

提交回复
热议问题