Entry
Does anyone else have problems using the \n newline escape character? why isn't it rendering for me?
Feb 18th, 2008 19:28
dman, Tim Stumbaugh, John Tinker, Dean K, Paul Coldrey, John S., http://www.ttnr.org
In HTML new lines are just like any other white space. The simplest way
to force HTML to go to the next line you must insert a '<br>' (break)
tag. HTML won't recognise more than one space, so simply having text on
a new line is ignored unless using the '<pre>' tag. '<pre>' will render
as fixed width (monospace) text in most browsers -- very few users
would change this setting anyway to something else. And it recognises
new lines as a new line, without <br>.
so if you have
echo "ecky \n phtang";
you should have
echo "ecky <br>\n phtang";
and then it will look OK in your browser
or
<pre>ecky
phtang</pre>
Also, remember that \n is only rendered when inside of double quotation
marks, like this: "\n". It will not be rendered when it is inside of
single quotation marks like this: '\n'.
Basically, \n is used for creating line breaks in the HTML output and
<br /> is used for creating line breaks in the browser rendering of that
HTML.
--------------------
If you already have a string, use echo nl2br("some string\n on a new
line"); to have php do the work for you