Recall & Review
beginner
What is heredoc syntax in PHP?
Heredoc is a way to write long strings in PHP without using quotes. It starts with
<<<IDENTIFIER and ends with the same IDENTIFIER on a new line. Variables inside heredoc are replaced with their values.Click to reveal answer
beginner
How does nowdoc syntax differ from heredoc in PHP?
Nowdoc is like heredoc but treats the content as plain text. It uses single quotes around the identifier like
<<<'IDENTIFIER'. Variables inside nowdoc are not replaced; they stay as text.Click to reveal answer
beginner
Show the correct way to end a heredoc or nowdoc string.
The ending identifier must be on a new line, start at the beginning (no spaces), and be followed by a semicolon. For example:<br>
IDENTIFIER;Click to reveal answer
beginner
Can you use variables inside heredoc and nowdoc? Explain.
In heredoc, variables are replaced with their values, just like in double-quoted strings.<br>In nowdoc, variables are not replaced; they are treated as plain text.
Click to reveal answer
beginner
Why use heredoc or nowdoc instead of regular quotes?
They make it easier to write long strings or text blocks without worrying about escaping quotes. Heredoc allows variable use, nowdoc is good for raw text.
Click to reveal answer
Which syntax allows variable parsing inside the string?
✗ Incorrect
Heredoc parses variables inside the string, replacing them with their values. Nowdoc treats everything as plain text.
How do you start a nowdoc string in PHP?
✗ Incorrect
Nowdoc starts with <<< followed by the identifier in single quotes, like <<<'IDENTIFIER'.
What must be true about the ending identifier in heredoc/nowdoc?
✗ Incorrect
The ending identifier must be at the start of a new line with no spaces or tabs before it.
Which of these is a benefit of using heredoc or nowdoc?
✗ Incorrect
Heredoc and nowdoc let you write multi-line strings without escaping quotes.
What happens to variables inside a nowdoc string?
✗ Incorrect
Variables inside nowdoc are not parsed and stay as plain text.
Explain how heredoc syntax works in PHP and when you might use it.
Think about writing a long message with variables inside.
You got /4 concepts.
Describe the difference between heredoc and nowdoc syntax.
One lets variables work, the other keeps text raw.
You got /4 concepts.