Skip to content
AgileLogics
3 min read

String Interpolation & Heredoc

Prerequisites: Strings

For a longer, multi-line string, heredoc avoids escaping quotes while still interpolating variables:

$name = "Ada";
$message = <<<TEXT
    Hello, $name!
    Welcome to PHP.
    TEXT;

echo $message;

Nowdoc (<<<'TEXT', with quotes around the identifier) behaves like single quotes — no interpolation at all — useful for embedding literal text with lots of $ signs.