Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print newline in PHP in single quotes

Tags:

string

php

I try to use single quotes as much as possible and I've noticed that I can't use \n in single quotes. I know I can just enter a newline literally by pressing return, but that screws up the indentation of my code.

Is there some ASCII character or something that I can type that will produce newline when I'm using single quotes?

like image 355
Matt Avatar asked Mar 28 '10 05:03

Matt


People also ask

Can you use single quotes in PHP?

Single or double quotes in PHP programming are used to define a string. But, there are lots of differences between these two. Single-quoted Strings: It is the easiest way to define a string. You can use it when you want the string to be exactly as it is written.

How do I add a new line to a string in PHP?

The nl2br() function inserts HTML line breaks (<br> or <br />) in front of each newline (\n) in a string.

Can we use \n in PHP?

?> Using new line tags: Newline characters \n or \r\n can be used to create a new line inside the source code.


1 Answers

No, because single-quotes even inhibit hex code replacement.

echo 'Hello, world!' . "\xA"; 
like image 157
Ignacio Vazquez-Abrams Avatar answered Oct 16 '22 02:10

Ignacio Vazquez-Abrams