Search code examples
phpapiheredoc

Inserting variables when using HEREDOC?


I'm making an API call to an email marketing service. One of the variables is "htmlContent" that has the HTML of the email to be sent.

Here's what my code looks like:

$htmlContent = <<<EOT
//lots of HTML code
<p>
EOT;

$htmlContent .= $player_name;

$htmlContent .= <<<EOT
</p>
//lots more HTML code
EOT;

I'm trying to insert the $player_name variable directly in between the <p></p> tags. When I add in this variable, my API call breaks. If I remove the variable addition, it works fine. What am I doing incorrectly?


Solution

  • Figured out I don't even need to break the EOT to enter the variable, I can just add {$player_name} directly in to the EOT code. Who would've known I was overcomplicating it...