3

Can I do a line break like this '\n'?

Or do I must use double quotes - "\n"?

Machavity
  • 30,841
  • 27
  • 92
  • 100
Run
  • 54,938
  • 169
  • 450
  • 748

4 Answers4

8

You have to use double quotes. Otherwise, PHP will literally output \n.

http://php.net/manual/en/language.types.string.php

Brad
  • 159,648
  • 54
  • 349
  • 530
3

just add

.PHP_EOL;

to the end of your line using single quotes and you will have a new line

Machavity
  • 30,841
  • 27
  • 92
  • 100
Ashraf
  • 717
  • 6
  • 11
3

To output a newline (or any other control character for that matter) you must always use double quotes.

An alternative to not use double quotes is chr() with the respective ASCII code as an argument:

echo chr(10); // same as echo "\n";
Alix Axel
  • 151,645
  • 95
  • 393
  • 500
1

No - \n in single quotes is '\n'.
Yes - you have to use double quotes.

deceze
  • 510,633
  • 85
  • 743
  • 889