Single quoted strings will display things almost completely “as is.” Variables and most escape sequences will not be interpreted. The exception is that to display a literal single quote, you can escape it with a back slash \'
, and to display a back slash, you can escape it with another backslash \\
(So yes, even single quoted strings are parsed).
Double quote strings will display a host of escape sequences (including some regexes), and variables in the strings will be evaluated. An important point here is that you can use curly braces to isolate the name of the variable you want evaluated. For example let’s say you have the variable $type
and you want to echo "The $types are"
. That will look for the variable $types
. To get around this use echo "The {$type}s are"
.
Single quotes inside of single quotes and double quotes inside of double quotes must be escaped:
$string = 'He said "What\'s up?"'; $string = "He said \"What's up?\"";