0

I want to use { in a string which is being stored in heredoc in PHP, how to use it? how to escape?

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

The output is Welcome Aayush Sinha

But the output required is Welcome {Aayush Sinha}.

Aayush Sinha
  • 377
  • 4
  • 18

1 Answers1

0

You should wrap it around another pair of curly braces

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

That will do the job.

Output: Welcome {Aayush Sinha}.

Aayush Sinha
  • 377
  • 4
  • 18