Page 1 of 1

Whats the deal with \n and why cant i get it to work!!!!

Posted: Thu Jul 30, 2009 8:25 am
by Buung
Hi all,

This is probably a bit of a newbie question but iv seen references to escaping characters in the training materials i am using such as \n , \t, \" etc. each time i try to use \n to start a new line the n simply gets removed from the output when i echo it to the web page. I am typing it as follows.

echo "I have never used this \n thingie and got it to work.";

:banghead:

Can anyone tell me if I am doing it wrong in some way?

Re: Whats the deal with \n and why cant i get it to work!!!!

Posted: Thu Jul 30, 2009 8:37 am
by Mark Baker
Web pages ignore the \n, \t, \r, etc, unless it's wrapped within <pre> or <xmp> tags. They also trim any amount of white space down to a single white space character
On a web page, use <br /> for a line break.

PHP even provide a function to automatically convert "\n" to <br />, the nl2br() function

Re: Whats the deal with \n and why cant i get it to work!!!!

Posted: Thu Jul 30, 2009 10:23 am
by Buung
Thanks i thought it may have had something to do with it being web output, you know iv looked it up in 3 different books and not one mentions anywhere about <pre> tags! thanks a lot for your help.