New Line on PHP CLI

后端 未结 4 539
暗喜
暗喜 2021-01-31 12:55

I have a php CLI script and cannot get the output to break on new lines. I do

echo \'this is my text\\r\\n\';
echo \'next line\';

This gives

相关标签:
4条回答
  • 2021-01-31 13:25

    Better not to concatenate anything in PHP, because it may lead to unexpected results, instead use a comma:

    echo 'Text with new line' , PHP_EOL;
    

    This will be faster too by the way: not concatenating and avoiding parsed double quotes.

    0 讨论(0)
  • 2021-01-31 13:41

    Use double quotes ".

    echo "next line\n";
    

    Additional you can use the system-dependent constant PHP_EOL

    echo "this is my text" . PHP_EOL;
    
    0 讨论(0)
  • 2021-01-31 13:42

    Use double quotes instead. ".

    0 讨论(0)
  • 2021-01-31 13:42

    Escape sequences are only parsed when inside double quotes, not single quotes.

    http://php.net/manual/en/language.types.string.php

    0 讨论(0)
提交回复
热议问题