Answer: In PHP to echo a new line or line break use ‘\r\n’ or ‘\n’ or PHP_EOL
If HTML uses
<br/> to create a line break, in PHP you can create a new line using 3 different methods :
1. PHP new line character ‘\n’ or ‘\r\n’
‘\n’ or ‘\r\n’ is the easiest way to embed newlines in a PHP string. Also, ‘\n’ can be used to create line breaks when creating PHP text files.
See the following example:
echo "Seegatesite.com\r\nThe best programming blog";
What is the difference ‘\n’ or ‘\r\n’ ?
\n Used to write a new line on a UNIX system, while Windows reads a new line with the \r\n character.
2.PHP_EOL: PHP Core Predefined Constants
PHP_EOL is predefined constants to translate the end of a line in PHP. Source : PHP Manual
echo "Create Line Break PHP" . PHP_EOL . "With PHP_EOL";
3. Using nl2br()
Used to add HTML line breaks in a string (the HTML code we usually use to create new lines
echo nl2br("Seegatesite.com \nsharing and learning programming");
The three methods above used according to your needs in creating new lines in PHP.