3
votes

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

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

4
Why do you want it with single quotes?Your Common Sense
because I use single quote to echo HTML like this '<ul class="pagination">' so I thought I could use single quote for \n.laukok
Why don't you test such a simple thing??Matthieu Napoli

4 Answers

8
votes

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

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

3
votes

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";
3
votes

just add

.PHP_EOL;

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

1
votes

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