Reputation: 10239
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:
echo($string.'\r');
Upvotes: 8
Views: 27037
Reputation: 80
The accepted answer not work for me.
my try is "\r\n"
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
Upvotes: 0
Reputation: 132
For the command line script, it's recommended to use PHP_EOL
.
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.
Upvotes: 2
Reputation: 1
PHP there are several many ways. But i think this is what you need
echo $array."<br>";
Upvotes: -1
Reputation: 1608
You can concatenate the PHP_EOL
constant.
echo 'Hi, Im great!' . PHP_EOL;
echo 'And Handsome too' . PHP_EOL;
Upvotes: 21
Reputation: 360922
You need to use double quotes:
echo($string."\r");
^ ^
single quoted strings do not honor ANY metacharacters, except the backslash itself.
Upvotes: 28