2

I'm currently starting to learn php off of Laracasts, and I have a very basic issue. My code is the following:

    <?php 
    echo 'Hello World';

In the video, this exact code outputs "Hello World", and then starts the terminal prompt on a new line.
He doesn't use /n or any other new line code
I wrote this same code on Sublime Text. When I run this in terminal, the echo'd "Hello World" displays, but it is on the same line as the next terminal prompt.
However, if I run the exact same code in a different text editor(I tried Visual Studio Code next) the "Hello World" displays, but the terminal prompt starts on a new line.
Wondering why this is happening in Sublime Text.

RockyB
  • 21
  • 2
  • 2
    Possible duplicate of [PHP - how to create a newline character?](https://stackoverflow.com/questions/4238433/php-how-to-create-a-newline-character) – aynber Apr 25 '19 at 12:38
  • Different terminals have different setups. Some of them will automatically add a new line after input, or running a function. On a normal command line, it will not automatically add a new line. – aynber Apr 25 '19 at 12:46
  • 1
    Thanks! You were right, he is using a different terminal! – RockyB Apr 25 '19 at 13:01

1 Answers1

3

You want to specify a new line character/carriage return.

In PHP you need to use double quotes like this: echo "Hello World\n";

more info on carriage returns here: \r\n, \r and \n what is the difference between them?

Windows and Linux both have their own interpretations, more information can be found in this informative post.

atoms
  • 2,993
  • 2
  • 22
  • 43
  • Thanks! Weird, I am watching the laracast video for php learning, and he doesn't include the /n or the double quotes, yet it still outputs it that same way. Can you explain this? – RockyB Apr 25 '19 at 12:43
  • 1
    Because on a terminal, the '\n' represent a new line – Fizik26 Apr 25 '19 at 12:51