Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newline in PHP command line

Tags:

php

newline

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');

like image 825
David Jones Avatar asked May 25 '12 14:05

David Jones


People also ask

Can we use \n in PHP?

?> Using new line tags: Newline characters \n or \r\n can be used to create a new line inside the source code.

What does N mean in PHP?

\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.

How do you add BR in Echo?

Answer: In PHP to echo a new line or line break use '\r\n' or '\n' or PHP_EOL.


1 Answers

You need to use double quotes:

echo($string."\r");
             ^  ^

single quoted strings do not honor ANY metacharacters, except the backslash itself.

like image 177
Marc B Avatar answered Sep 27 '22 20:09

Marc B