PHP: String Syntax

By Xah Lee. Date: . Last updated: .

Single Quote

String can be quoted by single quote.

echo 'sweet home';

Double Quote

String can also be quoted using a double quote. When using double quote, any variables in the form $variableName or ${variableName} will be evaluated and its value used.

$x = 3;
echo "I bet you\n ${x} dollars";

/* output:
I bet you
 3 dollars

Escape Character

Escape character sequence such as {\n, \r, \t} will also be interpreted when using double quote.

Quoting Long Text: Heredoc and Nowdoc