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');
?> Using new line tags: Newline characters \n or \r\n can be used to create a new line inside the source code.
\n is the newline or linefeed, other side \r is the carriage return. They differ in what uses them. Windows uses \r\n to signify the enter key was pressed, while Linux and Unix use \n to signify that the enter key was pressed.
Answer: In PHP to echo a new line or line break use '\r\n' or '\n' or PHP_EOL.
You need to use double quotes:
echo($string."\r");
^ ^
single quoted strings do not honor ANY metacharacters, except the backslash itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With