Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Aug 122010
 

Cross platform newline in PHP

Answer:

In PHP, if you want to print out a newline character, you can use the "\n" character

<?php

    echo "Hello World\n";

But the \n" character only work in Linux/UNIX, to make it work for both Windows, Mac and Linux/UNIX platforms, you can use a special constant PHP_EOL.

<?php

    echo "Hello World" . PHP_EOL;

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>