I am completely new to PHP and am doing online tutorials to learn. In this code:


$cars_on_lot = 10;

print "We have $cars_on_lot cars.\n

print "We got another new car.\n


print "Now we have $cars_on_lot cars!\n<p>";

print '<b>$cars_on_lot++</b> is the same to PHP as <b>$cars_on_lot + 1.</b>';


What does the "\n" mean?

This tutorial just all the sudden started using them without saying what the do-if anything...thanks!

8 Years
Discussion Span
Last Post by pritaeas

It is called a carriage return.
You can check out google for the full description.
In a nutshell, it is the return/enter key.
For the script it seems useless. a <br /> would be more beneficial.

I use the \n when I build HTML in my PHP code and I want it to look clean when viewing the source insead of one large clump of code.


echo = '<p>some text</p>'."\n";
echo = '<p>some more text</p>'."\n";

Will output:

<p>some text</p>
<p>some more text</p>

Without the \n it would output

<p>some text</p><p>some more text</p>

You don't need to use it for HTML but it comes in handy when creating CVS files or text emails, to name a couple.

Hope this helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.