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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Buung
Forum Newbie
Posts: 4
Joined: Thu Jul 09, 2009 8:14 am

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

Post 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?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

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

Post 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
Buung
Forum Newbie
Posts: 4
Joined: Thu Jul 09, 2009 8:14 am

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

Post 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.
Post Reply