Print newline in PHP in single quotes?

No, because single-quotes even inhibit hex code replacement echo ' world! ' . "\n.

No, because single-quotes even inhibit hex code replacement. Echo ' world! ' ."\n.

Ah ok.. I was hoping I wouldn't have to resort to that.. Thanks! – Matt Mar 28 '10 at 5:18 Matt:please accept the answer once you are done. – Kapil D Mar 28 '10 at 5:20 yessir.

He answered it in under 10 min. I had to wait till then to accept, then I forgot about it haha. – Matt Mar 28 '10 at 7:46.

FYI it is possible to get newlines into strings without double quotes: printf('Please%1$sgive%1$sme%1$snewlines%1$s', PHP_EOL); Which may be useful If your irrational fear of double quotes knows no bounds. Though I fear this cure may be worse than the disease.

It's not a fear.. you just get better performance when you use single quotes, so I try to use them more often then not.. but yah, this isn't really a great solution for this problem, its more trouble than its worth. Thanks. – Matt Mar 31 '10 at 13:03.

Echo 'hollow world' . PHP_EOL ; Then it is OS independent too.

If you are echoing to a browser, you can use with your statement: echo 'Will print a newline'; echo 'But this wont!

Unfortunately its more for terminal purposes.. thanks for your response though. – Matt Mar 28 '10 at 5:19 Not a problem, good luck. – Anthony Forloney Mar 28 '10 at 5:20.

Ah yes... but I still HATE the fact that VARIABLE at the end breaks all indentation in your code... I have ran into so many (stupid) errors using HEREDOC syntax – Matt Mar 28 '10 at 7:47.

No, according to documentation, PHP recognize no special symbol in single quotes. And there is no single reason to use single quotes as much as possible.

There is a slight performance increase to using single quotes. Also, it seems like a good practice to explicitly define when you want variables to be replaced. – Jackson Miller Mar 28 '10 at 5:42 1 @Jackson there is no performance increase.By any means.

Forget these childish rumors. And no, do talk not of variables, but of special sequences. If you want any sequence, a variable or a newline to be expanded - use double quotes, on it's purpose.

And OP's refusing to use it on it's purpose is nonsense. – Col. Shrapnel Mar 28 '10 at 6:03.

The only escape sequence you can use in single quotes is for the single quote itself. $foo = 'That\'s great'; The only way you could insert a new line into a string created with single quotes is to insert a literal newline $bar = 'That\'s cheating.

There IS a difference on using single VS double quotes in PHP e. G: 1. Echo '$var\n'; 2.

Echo "$var\n"; in 1, PHP will print literally: $var\n in 2, PHP will have to search the location in memory for $var, and return the value in that location, also, it will have to parse the \n as a new line character and print that result We're in the range of millionths of a second, but there IS a difference in performance. I would recommend you to use single quotes whenever possible, even knowing you won't be able to perceive this performance increase. But i'm a paranoic developer when it comes to performance.

I applaude you for trying to search the best way of doing this instead of using the double quotes solution A.K. A The lazy-developer-solution. – linuxdev Oct 9 at 0:57 The best way I know for doing what you want: echo 'foo', "\n"; – linuxdev Oct 9 at 0:59.

I would recommend you to use single quotes whenever possible, even knowing you won't be able to perceive this performance increase. But I'm a paranoid developer when it comes to performance.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions