• Notice regarding image hosts and attachments. See here.

How do you...

Soldato
Joined
16 Oct 2007
Posts
7,511
Location
UK
When writing PHP, how do you do it so that it shows a "

as a " finishes the thing i was doing.
If you get my newbish drift
 
this forum continues to teach me all sorts of useful tips

A nice way of being able to do both is by using the following. This is only really useful for big blocks of text as it uses 3 or more lines.

Code:
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.
 
Last edited:
What's the name of that technique above? (the <<< thing) I always forget.


Single quotes method is only good if the string your printing doesnt contain any variables though.

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 :p.
 
Back
Top Bottom