Nisi’s work blog

Nisi’s work blog – programing tips

New Line in PHP

Printing a new line witch is visible in a web page is made like this:

  1. echo(‘line 1′.\n.‘line 2′);
  2.  

the code above will print line 1 on a line and line 2 on a new line.

Now if you have to generate a CSV file  <br/> wil not work  you have to use  \n like in C language but there is a trick.

  1. echo (‘line 1 \n line 2′); //will print something like    line 1 \n line 2
  2. echo("line 2 \n line 2")// will print line 1 on the first line and line 2 on the second line

double quotes will parse \n as a new line and single quotes will believe is is a text