Reputation: 209
Is there any difference on this:
echo "</body>\n</html>";
and
echo "</body></html>";
I wonder if the 'newline' has any affect on browser.
Upvotes: 0
Views: 981
Reputation: 1772
There is no difference in your case. However, newline leads to anonymous text block insertion in case it is between two inline (or inline-block) elements:
<h2>Newline</h2>
<p>
<span>first</span>
<span>second</span>
</p>
<h2>No newline</h2>
<p>
<span>first</span><span>second</span>
</p>
<h2>newline in comment</h2>
<p>
<span>first</span><!--
--><span>second</span>
</p>
There're some techniques to avoid these blocks, like inserting comments or setting font-size: 0
for container element.
Lotta details might be found in the article.
Upvotes: 0
Reputation: 881
Yes, \n
does have effect on the output of your HTML. As you can see Here.
echo "</body>\n</html>";
outputs your HTML as:
</body>
</html>
while
echo "</body></html>";
outputs your HTML as
</body></html>
Upvotes: 2
Reputation: 133370
The
echo "</body>\n</html>";
have no echo in browser but you can see th effect in source code (the \n is not an html element and is not processed by browser
so you can see an effect in the code generated page (crtl+U) as
</body>
</html>
if you need an effect in browser you should use a proper tag as <br />
echo "</body><br /></html>"; // in this case poorly useful do the fact add a new line between a not (normally useful part
Upvotes: 0
Reputation: 753
The "\n" doesn't have any effect on the displayed html on the browser. If you want to go to the next line, echo a <br>
Upvotes: 2