如何在 heredoc PHP 中转义 { 和 }

How to escape { and } in heredoc PHP

我想在 PHP 中存储在 heredoc 中的字符串中使用 {,如何使用它?如何逃脱?

echo $heredoc = <<<HTML
<p>
    Welcome {$myname}
</p>
HTML;

输出为Welcome Aayush Sinha

但是需要的输出是Welcome {Aayush Sinha}

你应该用另一对花括号把它包起来

echo $heredoc = <<<HTML
<p>
     Welcome {{$myname}}
</p>
HTML;

这就够了。

输出:Welcome {Aayush Sinha}.