You can use the PHP newline characters \n or \r\n to create a new line inside the source code. However, if you want the line breaks to be visible in the browser too, you can use the PHP nl2br() function which inserts HTML line breaks before all newlines in a string.
Let's take a look at the following example to understand how it basically works:
<?php
echo "If you view the page source \r\n you will find a newline in this string.";
echo "<br>";
echo nl2br("You will find the \n newlines in this string \r\n on the browser window.");
?>
Note: The character \n writes a newline in UNIX while for Windows there is the two character sequence: \r\n. To be on safe side use the \r\n instead.
Use the Newline Characters '
\n' or '\r\n'You can use the PHP newline characters
\nor\r\nto create a new line inside the source code. However, if you want the line breaks to be visible in the browser too, you can use the PHPnl2br()function which inserts HTML line breaks before all newlines in a string.Let's take a look at the following example to understand how it basically works:
Note: The character
\nwrites a newline in UNIX while for Windows there is the two character sequence:\r\n. To be on safe side use the\r\ninstead.