PHP: String Syntax
Apostrophe Delimiter
Use APOSTROPHE delimiter for literal string.
<?php # APOSTROPHE quoted string's content is literal. # The \n is printed as blackslash and n echo 'hi there\n something'; ?>
QUOTATION MARK Delimiter
Use QUOTATION MARK delimiter for interpreted string.
When using QUOTATION MARK, any variables in the following forms are evaluated and its value used.
$variableName
{$variableName}
${variableName}
→ deprecated.
<?php $x = 4; # double quoted strings are interpreted. \n is a new line. Variable become values echo "I have $x apples"; // I have 4 apples ?>
<?php // string can contain Unicode characters, or literal line break echo "α β and ♥"; ?>
<?php $x = 3; $y = 4; echo "i have {$x} cats {$y} dogs"; # i have 3 cats 4 dogs ?>
Escape Sequence
the following characters has special meaning.
\n
→ new line\r
→ carriage return\t
→ tab