\n
is a new line character (a literal new line as you would type in your code).
$newline = "
";
var_dump($newline === "\n");
// true
You can also use the PHP constant PHP_EOL
(end of line). Note, that '\n'
will render \n
as a literal string; you must use double quotes to have it rendered as a new line character. Also note, that my above example may actually output false..since sometimes new lines are rendered as \r\n
.
<br />
is an HTML element for a line break. This will show up as a new line when HTML is rendered in a browser.
The only time that \n
will show up as a rendered line break in HTML, is when it is within a <pre>
(pre-formatted text) element. Otherwise it would be the same as just formatting/indenting your HTML code:
<?php
echo "<html>\n\t<body>\n\t\tHello World!\n\t</body>\n</html>";
Outputs:
<html>
<body>
Hello World!
</body>
</html>
` is html markup; `\n` is a unix newline – Mark Baker Jun 03 '14 at 22:53
``` in HTML as HTML does not honor whitespace – Dominik Jun 03 '14 at 22:53