How to Create a New Line in PHP

On this page, we are going to show you the simplest way of creating a new line in PHP.

You can do that by applying the PHP new line characters such as \r\n or \n within a source code.

Please, take into consideration, that if you wish the line breaks to be visible inside the browser, as well, you have the option of using the nl2br() function. This function is capable of inserting HTML line breaks before the new line inside the string.

To understand the basic principle, take a look at the example below:


echo "in case you are viewing the page source \r\n you will detect a newline inside this string.";
echo "<br>";
echo nl2br("You will detect the \n newlines inside this string \r\n on the window of the browser.");


Another important thing to mention: the \n character can write a new line within UNIX. At the same time, for Windows, the two character sequences exists like this: \r\n. So, we recommend you to use \r\n.