Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Line on PHP CLI

Tags:

php

People also ask

How do I add a new line in PHP?

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

How do you add BR in Echo?

write to text file"\n"; or echo "kings garden". "\n"; which adds a line break after the first line.

What is PHP CLI command?

PHP's Command Line Interface (CLI) allows you to execute PHP scripts when logged in to your server through SSH. ServerPilot installs multiple versions of PHP on your server so there are multiple PHP executables available to run.


Use double quotes ".

echo "next line\n";

Additional you can use the system-dependent constant PHP_EOL

echo "this is my text" . PHP_EOL;

Use double quotes instead. ".


Escape sequences are only parsed when inside double quotes, not single quotes.

http://php.net/manual/en/language.types.string.php


Better not to concatenate anything in PHP, because it may lead to unexpected results, instead use a comma:

echo 'Text with new line' , PHP_EOL;

This will be faster too by the way: not concatenating and avoiding parsed double quotes.