echo "This is a double-quote: \".";
echo 'This is a double-quote: ".';
I use the single quotes method, took me blooming ages to realise I could do that, its crept in a lot of my code now
Single quotes method is only good if the string your printing doesnt contain any variables though.
this forum continues to teach me all sorts of useful tips
this forum continues to teach me all sorts of useful tips
echo <<< HTML
This can contain $variables and " and nothing needs escaping :)
HTML;
//or we can store it in a variable to start with
$another_variable = <<< MOREHTML
some more text with variables $my_html and "
MOREHTML;
//HTML and MOREHTML can be any label you want.
Single quotes method is only good if the string your printing doesnt contain any variables though.
$var1='bananas'; $var2='pancakes';
echo sprintf('I use single quotes but can also display variables, such as %s or %s!', $var1, $var2);
PHP:$var1='bananas'; $var2='pancakes'; echo sprintf('I use single quotes but can also display variables, such as %s or %s!', $var1, $var2);
Kind of, anyway.
Single quotes method is only good if the string your printing doesnt contain any variables though.
What's the name of that technique above? (the <<< thing) I always forget.
I'd say it's useful unless the string contains variables.
Heredoc.