i'm writing this:
echo "foo";
echo "\n";
echo "bar";
and "bar" is not written in the line below.
What am i doing wrong?
Javi
i'm writing this:
echo "foo";
echo "\n";
echo "bar";
and "bar" is not written in the line below.
What am i doing wrong?
Javi
We can apply
\n
in php by using two typeUsing CSS
Which tells the browser to preserve whitespace so that
Result:
Using
nl2br
nl2br
: Inserts HTML line breaks before all newlines in a stringResult
If you want a new line character to be inserted into a plain text stream then you could use the OS independent global PHP_EOL
In HTML terms you would see a newline between foo and bar if you looked at the source code of the page.
ergo, it is useful if you are outputting say, a loop of values for a select box and you value having html source code which is "prettier" or easier to read for yourself later. e.g.
if your text has newlines, use nl2br php function:
This should look good in browser
Since it wasn't mentioned, you can also use the CSS white-space property
Which tells the browser to preserve whitespace so that
Would display
We can use \n as a new line in php.
Code Snippet :
Output: