Reputation: 13
if im not wrong \n
representation means that a newline as <br>
.But when i use <br>
or another tags they work properly but escape sequences.
example
echo "write somethings<br>";
echo "about coding";
above example works fine but when i try to use escape sequences none of them are not working
echo "write something\n";
echo "about coding";
it's just an example for newline character and the other escaping characters dont work as \n
.What is the real logic on this case?
Upvotes: 0
Views: 1912
Reputation: 300825
HTML ignores carriage return and linefeed characters, treating them as whitespace. If you want to use display a string formatted with "\n"
you can use nl2br to convert it, e.g.
echo nl2br("this is on\ntwo lines");
Upvotes: 1
Reputation: 438
If you look at this in the browser it wont work : browser knows only HTML for display (<br>
) but not escape like \n
or \r
Upvotes: 0
Reputation: 943142
No, this is an example of HTML rules.
Putting \n
in a PHP string and then outputting it as HTML will put a new line character in the HTML source code. It's just line pressing return when writing raw HTML.
HTML puts no special meaning on the new line character (at least outside of script elements and elements with various non-default values of the CSS white-space property) and treats it like any other white space character.
<br>
, on the other hand, is a line break element (but usually an indication that you should be using a block level element around the content instead).
Upvotes: 1
Reputation:
\n
and other similar escape sequences are not part of HTML. You should use HTML escape sequences. These can be found here: http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php
So only your <br>
tag works but \n
is not
Upvotes: 1