faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

39 of 52 people (75%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Does anyone else have problems using the \n newline escape character? why isn't it rendering for me?

Nov 27th, 2008 02:23
healthy man, 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
http://www.healthdothealth.com
http://www.healthxhealth.com
http://www.mesotheliomainmesothelioma.com
http://www.healthfirewall.com
http://www.flathealth.com
http://www.healthbodyguard.com