Xah Lee, 2007-11, 2011-04-01
String literals can be quoted by a single quote character.
<?php echo 'hi, sweetie'; ?>
String can also be quoted using a double quote. When using double quote, any variables in the form ${varName} will be evaluated and its value used.
<?php $x = 3; echo "Hi, i bet you ${x} dollars"; ?>
If you have a large block of text, you can use a form called “heredoc”.
You start the quote delimiter by <<<anyStringABC and end it by anyStringABC; on a line by itself. Example:
<?php $shakespeare = <<<EOT “Fondling,” she saith, “since I have hemm'd thee here Within the circuit of this ivory pale, Ill be a park, and thou shalt be my deer; Feed where thou wilt, on mountain or in dale: Graze on my lips; and if those hills be dry, Stray lower, where the pleasant fountains lie.” EOT; echo $shakespeare; ?>
Basically, the “heredoc” mechanism of quoting is for when you have a large block of text (such as a template) that may itself contain many single quotes or double quotes. You start the quote using a string “EOT” as the delimiter, and the parser will end the quote when it encounter that string again. The “EOT” can be any arbitrary string. Variables inside heredoc will still be interpreted.
blog comments powered by Disqus