Run
Run

Reputation: 57176

Making a new line with single quotes?

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

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

Upvotes: 3

Views: 9556

Answers (4)

Ashraf
Ashraf

Reputation: 747

just add

.PHP_EOL;

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

Upvotes: 3

Alix Axel
Alix Axel

Reputation: 154513

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

Upvotes: 3

deceze
deceze

Reputation: 522016

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

Upvotes: 1

Brad
Brad

Reputation: 163301

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

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

Upvotes: 8

Related Questions