Skip to content
PHP Logo

How can heredoc syntax be utilized for including function calls within strings in PHP templates?

To include function calls within strings in PHP templates, you can utilize heredoc syntax. This allows you to easily embed dynamic content, such as function calls, within your strings without the need for complex concatenation. Simply define the heredoc block and include your function calls within the block as needed.

php
<?php

$name = "John";

// Using heredoc syntax to include function calls within a string
$output = <<<EOD
Hello, $name! Today is <?= date('l') ?>.
EOD;

echo $output;
?>