I was studying php with tutorial. I recognized that in php
is sometimes use like this
echo $myString."<br />"
Suddenly, there came another in the tutorial "\n" and I got confused. Can I use it just like I use
<br />
?
So like this?
echo $mySting."\n"
Is it like a html tag? What's the difference between
<br /> and \n?
<br />
is a HTML line-break, whereas \n
is a newline character in the source code.
In other words, <br />
will make a new line when you view the page as rendered HTML, whereas \n will make a new line when you view the source code.
Alternatively, if you're outputting to a console rather than somewhere that will be rendered by a web browser then \n
will create a newline in the console output.
\n
is a new line feed within the context of plain text, while <br />
is line break within the context of HTML.
HTML can interpret \n
when using preformatted blocks (e.g. <pre>
), but it does not by default, and should not unless there is a specific use case (like when quoting, citing poetry, or showing code).
<br />
should never be used to separate text that should otherwise be treated as a paragraph, heading or other group of text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With