PHP variable insertion inside EOT

I want to insert a variable inside EOT but it doesn't work (I'm new to php, maybe why). This code is part of the script when I only echo $username shows the real name, but when I put it inside the EOT, plain text is displayed, not the real name.

What am I doing wrong?

 $username=getUsername($ID); echo <<<'EOT' Some HTML code goes here Hello $username, welcome back! Some HTML code goes here EOT; 
+8
variables php
source share
2 answers

You must leave single quotes here:

 echo <<<'EOT' 

This means the option 'nowdoc , which does not interpolate variables.

But you need the original "heredoc" syntax without quotes:

 echo <<<EOT 
+21
source share
 $variable = 'text'; echo <<<EOT Some {$variable} here EOT; 
+7
source share

All Articles