I’m running a PHP script via the command line and trying to get output printed on new lines. I’ve tried all of the usual suspects (
\n,\r,\l) but nothing is working. I’m accessing my Ubuntu server using PuTTY over SSH. Here’s my code:
You need to use double quotes:
echo($string."\r"); ^ ^
single quoted strings do not honor ANY metacharacters, except the backslash itself.
You can concatenate the
echo 'Hi, Im great!' . PHP_EOL; echo 'And Handsome too' . PHP_EOL;
Use double quotes echo “next line\n”;
For the command line script, it’s recommended to use
Please refer http://php.net/manual/en/reserved.constants.php
PHP_EOL (string) The correct 'End Of Line' symbol for this platform. Available since PHP 5.0.2
It make your script executable across platform.
PHP there are several many ways. But i think this is what you need
The accepted answer not work for me.
my try is
echo 'This is some text before newline'; echo "\r\n"."text in new line"; //OR echo 'This is some text before newline'."\r\n"."text in new line";
cmd output will be:
This is some text before newline
text in new line